markdown图片转换demo
markdown图片转换demo
一直以来都是用Markdown来写博客的,但是它的图片嵌入实在是太让人头秃,逼得我能找网上的图片就不用自己的,实在是麻烦。所以我在发现了一个可以生成markdown样式的图床后就写了一个小程序,花了2个小时左右。平常把编辑器文件夹的图片(一般是截图)上传上去,再把markdown形式的链接保存到文件里,然后进行转换。当然有很多限制,比如没有图形化界面(过一阵闲下来就去学Qt),软件必须依赖一个配置文件;没有调用图床的API而是每次需要手动上传(因为白嫖的图床,感觉不太好);需要先把要修改的文档拷贝到配置文件设定的txt文件中(还是因为不会Qt,终端里面输入我觉得太反人类了),然后生成到另一个txt文件中。之后学会Qt、找到了正规图床之后可能会改改吧。
/*
*该程序是用来处理markdown文档上传时,图片上传问题的(用于更名)
*/
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
string getPartOfString(string& input,char dot){
string ans;
int index=0;
while(input[index]!=dot)
index++;
for(int i=index+1;i<input.length();i++){
ans+=input[i];
}
return ans;
}
void readFile(string* inputTextPath,string* outputTextPath,string* outputPicturePath){
vector<string*>saveString;
saveString.push_back(inputTextPath);
saveString.push_back(outputTextPath);
saveString.push_back(outputPicturePath);
cout << "------欢迎使用Markdown上传程序-----------\n本软件只支持类Github可生产markdown图片格式的图床\n" << endl;
ifstream in("setPicturePath.txt");
string tempRead;
char tempChar;
while(!in.eof()){
in>>tempRead;
cout<<tempRead<<endl;
tempRead.clear();
}
in.close();
cout<<"这是当前的配置,您要使用吗,如果不要赶快去改!\n改完了输入y确认"<<endl;
cin>>tempChar;
while(tempChar!='y'){
cout<<"请输入y"<<endl;
cin>>tempChar;
}
cout<<"是否已将所需文件写入指定地点,是请输入y"<<endl;
cin>>tempChar;
while(tempChar!='y'){
cout<<"完成请输入y"<<endl;
cin>>tempChar;
}
ifstream in2("setPicturePath.txt");
//cout<<in2.is_open()<<endl;
for(int i=0;i<3;i++){
in2>>tempRead;
saveString[i]->append(getPartOfString(tempRead,'\:'));
cout<<"saveString[i]="<<&saveString[i]<<endl;
}
in2.close();
}
class afterPicture{
public:
string nameWithoutType;
string fullName;
afterPicture(string fullname,string namewithoutType){
fullName=fullname;
nameWithoutType=namewithoutType;
}
};
void readPicture(string& outputPicturePath,vector<afterPicture*>& afterPictureVector){
ifstream in(outputPicturePath);
string tempFullPath;
string tempPathNoType;
int tempIndex=0;
while(!in.eof()){
in>>tempFullPath;
tempIndex=0;
while(tempFullPath[tempIndex]!='[')
tempIndex++;
tempIndex++;
while(tempFullPath[tempIndex]!=']'){
tempPathNoType+=tempFullPath[tempIndex];
tempIndex++;
}
afterPictureVector.push_back(new afterPicture(tempFullPath,tempPathNoType));
tempFullPath.clear();
tempPathNoType.clear();
}
in.close();
}
string search(string& inputPicturePath,vector<afterPicture*>&afterPictureVector){
int length=afterPictureVector.size();
for(int i=0;i<length;i++){
if(inputPicturePath==afterPictureVector[i]->nameWithoutType)
return afterPictureVector[i]->fullName;
}
return "";
}
void readText(string& inputTextPath,string& outputTextPath,vector<afterPicture*>&afterPictureVector){
ifstream in(inputTextPath);
ofstream out(outputTextPath);
char tempChar;
string searchString;
string searchAns;
bool flag=false;
while(!in.eof()){
tempChar=in.get();
if (tempChar == '!')
{
tempChar = in.get();
if (tempChar == '[')
{
tempChar=in.get();
while (tempChar != ']')
{
searchString+=tempChar;
tempChar=in.get();
}
searchAns=search(searchString,afterPictureVector);
if(searchAns.length()>2)
out<<searchAns;
else
{
out<<"!["<<searchString<<"]";
flag=true;
}
searchString.clear();
if(!flag){
while(tempChar!=')')
tempChar=in.get();
tempChar=in.get();
}else
{
while(tempChar!=')'){
tempChar=in.get();
out<<tempChar;
}
tempChar=in.get();
out<<tempChar;
flag=false;
}
}
else
{
out<<'!'<<tempChar;
}
}
else
{
out<<tempChar;
}
}
in.close();
out.close();
}
int main(){
string inputTextPath;
string outputPicturePath;
string outputTextPath;
vector<afterPicture*> afterPictureVector;
readFile(&inputTextPath,&outputTextPath,&outputPicturePath);
readPicture(outputPicturePath,afterPictureVector);
readText(inputTextPath,outputTextPath,afterPictureVector);
cout<<"处理完毕!"<<endl;
return 0;
}
配置文件长这个样子:
输入文档的地址:E://textNeedChange.txt
输出文档的地址:E://textChanged.txt
输出图片的地址:E://afterChangePicture.txt
markdown图片转换demo的更多相关文章
- android 的数学公式图片转换
在应用中的数学公式是不能直接以文本显示和输入的,包括在一些学习类网站上看到的公式,他们都是以gif图片的形式展示出来的.而怎么样生成各种各样的gif图片形式的数学公式呢,此处未作深入研究,我所知道的是 ...
- 使用CSS将图片转换成黑白(灰色、置灰)z转
小tip: 使用CSS将图片转换成黑白(灰色.置灰) by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.c ...
- 小tip: 使用CSS将图片转换成模糊(毛玻璃)效果
去年盛夏之时,曾写过“小tip: 使用CSS将图片转换成黑白”一文,本文的模式以及内容其实走得是类似路线.CSS3 → SVG → IE filter → canvas. 前段时间,iOS7不是瓜未熟 ...
- Base64 图片转换工具
以前在写asp的后台的时候,有一个上传功能是必须的,那时候进行的图片预览(未上传前)其实就是获取本地的图片路径来显示图片,但是随着HTML5的出现,可以把图片通过编码来实现预览. 在雅虎的36条速度优 ...
- [转] 小tip: 使用CSS将图片转换成模糊(毛玻璃)效果 ---张鑫旭
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=3804 去年盛夏之时, ...
- 小tip: 使用CSS将图片转换成黑白(灰色、置灰)[转]
小tip: 使用CSS将图片转换成黑白(灰色.置灰) 这篇文章发布于 2012年08月19日,星期日,20:41,归类于 css相关, SVG相关. 阅读 159943 次, 今日 146 次 ...
- Md2All:好用的markdown文件转换工具,文章迁移微信公众号的利器
目录 简介 使用体验 极速上手 更多功能 总结 简介 markdown以简单的语法和强大的功能,征服了无数技术创作者,几乎主流的技术博客网站都开始支持markdown语言撰写博客.但是微信公众号的文章 ...
- Markdown 图片助手-MarkdownPicPicker
title: Markdown 图片助手 v0.1 toc: true comments: true date: 2016-06-04 16:40:06 tags: [Python, Markdown ...
- ios学习-制作一个浏览图片的Demo
一.项目要求:制作一个浏览图片的Demo,要求包含夜间模式,以及改变图片大小,能够显示不同的图片描述 二.开发步骤: 1.在storyboard上添加一个空白的View,然后添加”设置“按钮,添加im ...
随机推荐
- thinkphp session 跨域问题解决方案
session 跨域,困扰我好几天,今天终于弄明白了! 不管是thinkphp ,还是本身的php 其实都要设置session.cookie_domain 设置好,就OK了 在thinkphp 里,在 ...
- laravel 框架接入环信遇到的坑(-)
在脚本中执行判断user表中是否注册环信时,报错: “请求错误:service_resource_not_found Service resource not found ” // 判断环信是否已经 ...
- 最少步数&P1443 马的遍历
1330:[例8.3]最少步数 s数组:记录(1,1)到达每一点需要的最少步数 s[1][1]自然为 0,其余初始化为 -1 que数组:que[#][1] 表示(1,1)可到达点的 x 坐标 q ...
- 一、Vue基础之常用方法
一.JSON.parse() 与 JSON.stringify() 1.JSON.parse() :是从一个字符串中解析出 json 对象 //定义一个字符串 var data='{"nam ...
- invalid new-expression of abstract class type 'CurveFittingEdge'
目录 一 报错原因 注:原创不易,转载请务必注明原作者和出处,感谢支持! 一 报错原因 今天遇到了一个之前从未遇到的报错: error: invalid new-expression of abstr ...
- if、elif 条件判断
#!/usr/bin/python #-*- codinig: UTF-8 -*- from __future__ import print_function import os, sys, stat ...
- js Date格式转化
Date格式转化为日期 年-月-日(格式随意修改) GetDateStr(dd, AddDayCount) { dd.setDate(dd.getDate() + AddDayCount)// 获取 ...
- ubuntu查看目录大小
du -h --max-depth=1 该命令会查看目录下的所有子目录大小,以及目录总共占用磁盘空间
- cisco路由的ip静态路由添加(二)
路由器Corp 配置Corp(config)#ip route 192.168.20.0 255.255.255.0 10.1.3.2 150 Corp(config)#ip route 192.16 ...
- Git_mergetool_tutorial(转载)
原文链接:https://gist.github.com/karenyyng/f19ff75c60f18b4b8149#table-of-content Table Of Content Skip t ...