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的更多相关文章

  1. android 的数学公式图片转换

    在应用中的数学公式是不能直接以文本显示和输入的,包括在一些学习类网站上看到的公式,他们都是以gif图片的形式展示出来的.而怎么样生成各种各样的gif图片形式的数学公式呢,此处未作深入研究,我所知道的是 ...

  2. 使用CSS将图片转换成黑白(灰色、置灰)z转

    小tip: 使用CSS将图片转换成黑白(灰色.置灰) by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.c ...

  3. 小tip: 使用CSS将图片转换成模糊(毛玻璃)效果

    去年盛夏之时,曾写过“小tip: 使用CSS将图片转换成黑白”一文,本文的模式以及内容其实走得是类似路线.CSS3 → SVG → IE filter → canvas. 前段时间,iOS7不是瓜未熟 ...

  4. Base64 图片转换工具

    以前在写asp的后台的时候,有一个上传功能是必须的,那时候进行的图片预览(未上传前)其实就是获取本地的图片路径来显示图片,但是随着HTML5的出现,可以把图片通过编码来实现预览. 在雅虎的36条速度优 ...

  5. [转] 小tip: 使用CSS将图片转换成模糊(毛玻璃)效果 ---张鑫旭

    by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=3804 去年盛夏之时, ...

  6. 小tip: 使用CSS将图片转换成黑白(灰色、置灰)[转]

        小tip: 使用CSS将图片转换成黑白(灰色.置灰) 这篇文章发布于 2012年08月19日,星期日,20:41,归类于 css相关, SVG相关. 阅读 159943 次, 今日 146 次 ...

  7. Md2All:好用的markdown文件转换工具,文章迁移微信公众号的利器

    目录 简介 使用体验 极速上手 更多功能 总结 简介 markdown以简单的语法和强大的功能,征服了无数技术创作者,几乎主流的技术博客网站都开始支持markdown语言撰写博客.但是微信公众号的文章 ...

  8. Markdown 图片助手-MarkdownPicPicker

    title: Markdown 图片助手 v0.1 toc: true comments: true date: 2016-06-04 16:40:06 tags: [Python, Markdown ...

  9. ios学习-制作一个浏览图片的Demo

    一.项目要求:制作一个浏览图片的Demo,要求包含夜间模式,以及改变图片大小,能够显示不同的图片描述 二.开发步骤: 1.在storyboard上添加一个空白的View,然后添加”设置“按钮,添加im ...

随机推荐

  1. LeetCode 86. 分隔链表(Partition List)

    题目描述 给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前. 你应当保留两个分区中每个节点的初始相对位置. 示例: 输入: head = 1-> ...

  2. 如何使用Heartbeat,组建一个高可用性的mysql集群

    转了好多次帖子,其实就是为了使用heartbeat来搭建mysql集群,网上很多都是用make来生成RPM来安装,我也找了很多资料,mysql 自带的cluster用户不满意,只能再次vmware虚拟 ...

  3. 更换django自带的下载链接

    class Case(models.Model): file_type = MyFileField(verbose_name='file_obj', max_length=256, blank=Tru ...

  4. SSD 页、块、垃圾回收

    基本操作: 读出.写入.擦除: 因为NAND闪存单元的组织结构限制,单独读写一个闪存单元是不可能的.存储单元被组织起来并有着十分特别的属性.要知道这些属性对于为固态硬盘优化数据结构的过程和理解其行为来 ...

  5. LC 358. Rearrange String k Distance Apart

    Given a non-empty string s and an integer k, rearrange the string such that the same characters are ...

  6. url protocol

    首先注册服务 方法1,保存为reg文件直接执行,需要按需修改路径 Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\EasyPrint] ...

  7. Git代码行数统计命令

    统计zhangsan在某个时间段内的git新增删除代码行数 git log --author=zhangsan--since=2018-01-01 --until=2019-04-01 --forma ...

  8. 系统启动热键(Boot Hotkey)

    1.HP ENVY 13 F1 --> 系统信息F2 --> 系统检测F9 --> 启动设备选项F10 --> 设置BIOSF11 --> 系统恢复ENTER --> ...

  9. 【机器学习实践】Jupyter Notebook安装 侧边导航栏功能 操作及其他常用扩展功能介绍

    安装过程:  1. 首先我们引入jupyter_contrib_nbextension这个第三方库. 2. 在Anaconda Promot中输入命令: pip install jupyter_con ...

  10. HttpClient常用方法总结

    1.HttpPost发送表单请求 String url = ""; HttpPost httpPost = new HttpPost(url); List<NameValue ...