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. Python 之 subprocess模块

    一.subprocess以及常用的封装函数运行python的时候,我们都是在创建并运行一个进程.像Linux进程那样,一个进程可以fork一个子进程,并让这个子进程exec另外一个程序.在Python ...

  2. 【Java笔试】OYO校招Java工程师|牛客平台,算法:字符串翻转。附选择题解析

    文章目录 1.Java笔试算法题:字符串翻转 2.单选题: 2.1.同一进程下的多个线程可以共享哪一种资源:data section 2.2.一个树形的叶结点在前序遍历和后序遍历下,可以相同的相对位置 ...

  3. 利用uniGUI中的TUniPageControl实现多页面

    远行效果: 实现代码: procedure TfrmMain.OpenForm(Caption,FormClassName:string);var  i:integer;  sheet:TUniTab ...

  4. JS判定数据类型

    1.typeof                我们能够使用typeof判断变量的身份,判断字符串得到string,数字和NaN得到number,函数会得到function等,但是判断数组,对象和nu ...

  5. 如何查看MySQL connection id连接id

    每个MySQL连接,都有一个连接ID,可以通过 connection_id()查看. 连接id也可以通过以下方式查看: show processlist中id列 information_schema. ...

  6. Ceph 的用户管理与认证

    目录 文章目录 目录 前言 Ceph 的用户管理 用户管理常规操作 CephX 认证系统 身份认证原理 使用 ceph-authtool 进行密钥环管理 注意事项 前言 常规的身份认证系统无非三点: ...

  7. 基于 Open vSwitch 的 OpenFlow 实践

    目录 文章目录 目录 前文列表 Open vSwitch 基本概念 Open vSwitch 与 OpenFlow 的关系 通过 Open vSwitch 实践 OpenFlow 屏蔽数据包 重定向数 ...

  8. shaderToy学习篇

    觉得shadertoy上的一些网友的作品写得很好,加上自己对glsl一些内置函数,内置变量不是很熟悉,于是决定开始学习一下上面一些大佬的代码. 今天的案例是这个: 附上shaderToy的地址:htt ...

  9. java数据结构之ArrayList

    一.ArrayList源码注释 /** * ArrayList源码分析,jdk版本为1.8.0_121 */ public class ArrayList<E> extends Abstr ...

  10. hibernate之inverse=true相关配置讲解

      首先inverse=”true”是在双向关联里面使用单向关联没有这个配置 inverse – 标记由哪一方来维护关联关系(双向关联中会用到) inverse默认值为false 如果inverse设 ...