为了简化CSDN写博客的字体问题,给出一段代码,用于处理使用默认格式写完博客后,处理一次来解决字体问题。
代码片段
代码片段如下所示:
#include <iostream>
#include <string>
#include <fstream>
#include <strstream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char **argv)
{
if (3!=argc)
{
cerr << "[ ERROR ] error using this application" << endl;
cerr << "[ HELP ] " << argv[0] << " " << "inpute_filename output_filename" << endl;
return -1;
}
vector<wstring> newFileContains;
wifstream infile(argv[1], wifstream::ios_base::in);
if (!infile.is_open())
{
cerr << "[ ERROR ] failed to open the file of " << argv[1] << endl;
return -1;
}
wstring lines;
int cpos;
while(!infile.eof())
{
std::getline(infile, lines);
cpos = lines.find(wstring(L"<p>"));
if (cpos!=wstring::npos)
{
lines.append(L"<span style=\"font-family:Microsoft YaHei;font-size:16px;\">");
wcout << lines << endl;
newFileContains.push_back(lines);
continue;
}
cpos = lines.find(wstring(L"</p>"));
if (cpos!=wstring::npos)
{
lines.insert(0, wstring(L"</span>"));
wcout << lines << endl;
newFileContains.push_back(lines);
continue;
}
newFileContains.push_back(lines);
}
infile.close();
wofstream oufile(argv[2], wofstream::ios_base::out);
if (!oufile.is_open())
{
cerr << "[ ERROR ] failed to open the file of " << argv[2] << endl;
return -1;
}
for (size_t i = 0; i < newFileContains.size(); i++)
{
oufile << newFileContains[i] << endl;
}
oufile.close();
return 0;
}
使用方法
当然应该先编译上面的代码,做成可执行程序。
第二步,在CSDN写博客,写完之后点击下图中红色箭头指示的位置。
点击后,全选编辑框中的内容,拷贝到txt文件中,在命令行中执行编译好的可执行程序。将输出文件的内容覆盖掉自己刚才选中的内容。
再调整
有些地方可能会有问题,比如代码后面的行,手动调整下就好了。至于标题,也是要自己修改的。