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. 备忘录:“#ifdef __cplusplus extern "C" { #endif”的定义

    看一些程序的时候老是有“#ifdef __cplusplusextern "C" {#endif”的定义,搞搞清楚是怎么回事: Microsoft-Specific Predefi ...

  2. LeetCode 470. 用 Rand7() 实现 Rand10()(Implement Rand10() Using Rand7())

    题目描述 已有方法 rand7 可生成 1 到 7 范围内的均匀随机整数,试写一个方法 rand10 生成 1 到 10 范围内的均匀随机整数. 不要使用系统的 Math.random() 方法. 示 ...

  3. Memcached 在Windows和Linux的安装和使用

    Memcached 把经常操作的数据导入到内存中 Memcached是一个高性能的支持分布式的内存存储系统,可以看成一个巨大的hash表.形式:key->value key(唯一键值string ...

  4. 安装 redis manager

    安装文档在redis manager 的官方文档上有,这里做个笔记.官网地址:https://snapcraft.io/redis-desktop-manager 截图1: 可以选择自己的系统,根据里 ...

  5. Collapse 折叠面板

    通过折叠面板收纳内容区域 基础用法 可同时展开多个面板,面板之间不影响 <el-collapse v-model="activeNames" @change="ha ...

  6. 搭建Git服务器及本机克隆提交

    前文 Git是什么? Git是目前世界上最先进的分布式版本控制系统. SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己的电脑,所以首 ...

  7. Jenkins笔录

    1.Linux下安装jdk8的方法 ,只需要一条命令就可以安装jdk: yum install java-1.8.0-openjdk* -y 执行过这条命令无需配置,直接可以使用. 2.JDK12版本 ...

  8. python programming GUI综合实战(在GUI上画图)

    import os import platform import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5 ...

  9. windows server 2008 R2 怎么集成USB3.0驱动

    DELL最新出的T130.T330.R230.R330四款服务器新增了USB3.0功能,在安装2008 R2系统镜像需要集成USB3.0才能安装,不然鼠标和键盘动不了 先在D盘创建一个文件夹Temp, ...

  10. (转) pip Fatal error in launcher: Unable to create process using

    接上篇“Eclipse启动报错:JVM terminated. Exit code=2”,今天把Python的安装位置也从C盘剪切到了D盘, 然后修改了Path环境变量中对应的盘符:D:\Python ...