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 ...
随机推荐
- word 之 插入删除空行
好久没有写程序了.有些手生: 在用C#对word进行直接开发操作过程中,为了文档的美观,我们会插入或删除空行. 1.插入空行的代码很简单. Selection 类型的TypeParagraph()函数 ...
- 后盾网lavarel视频项目---lavarel中的tinker是什么
后盾网lavarel视频项目---lavarel中的tinker是什么 一.总结 一句话总结: 是用来调试laravel,可以打印变量或对象信息,显示函数代码,对数据库写入和查询数据 laravel中 ...
- Java-数据类型与编码(ASCII、Unicode 和 UTF-8)
机械硬盘硬件结构(了解)https://diy.pconline.com.cn/cpu/study_cpu/1009/2215404_all.html 一.数据储存单位 1.bit(位) https: ...
- Nginx服务应用
虚拟主机 基于域名的虚拟主机 所谓基于域名的虚拟主机,意思就是通过不同的域名区分不同的虚拟主机,基于域名的虚拟主机是企业应用最广的虚拟主机类型,几乎所有对外提供服务的网站都是使用基于域名的虚拟主机 基 ...
- Scope 'request' is not active for the current thread
Unable to instantiate Action, getUserAction, defined for 'getUser' in namespace '/'Error creating be ...
- LC 954. Array of Doubled Pairs
Given an array of integers A with even length, return true if and only if it is possible to reorder ...
- C++学习 之 初识变量和基本类型 之 内置类型
声明: 本人自学C++, 没有计算机基础,在学习的过程难免会出现理解错误,出现风马牛不相及的现象,甚至有可能会贻笑大方. 如果有幸C++大牛能够扫到本人的博客,诚心希望大牛能给予 ...
- ORA-39095: Dump file space has been exhausted
ORA-39095: Dump file space has been exhausted Table of Contents 1. 简述 2. 错误信息 3. 分析 4. 解决 5. 扩展 1 简述 ...
- 使用Statement对象执行静态sql语句
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java ...
- FTP\SFTP连接命令
五.ftp连接 输入:ftp 10.18.49.19 2121六.输入账号密码 zhangsan/sdjg34t#七.输入:ls 查看文件是否上传 如上传 输入:bye ...