|
这两研究了一下怎么更改博客园代码显示,没有学过前端,感觉好麻烦,引用这引用那的
或者用windows live writer来进行写,但是mac用户好悲催....
用别人的win电脑试了一下live writer贴出的代码效果,原来只不过是在html代码前后加了两句话,然后其中的 <>全部换掉就可以了
求人不如求自己, 还是写一个小程序,转换一下吧, 写的很粗糙,而且用c写的,用到了一些linux系统调用,mac下也可以.
用的时候只要新建一个文件,在文件中写入想贴的代码,然后运行 a.out 文件名
之后会新建一个 exchangedCode.txt的文件,把这个文件里的内容直接复制出来,贴到博客园中就可以了(要在html模式中贴..)
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
char head[] = "<pre class=\"brush: cpp; auto-links: true; collapse: false; first-line: 1; gutter: true; html-script: false; light: false; ruler: false; smart-tabs: true; tab-size: 4; toolbar: true;\">";
char tail[] = "</pre>";
void exchange(char *p_file){
char temp[2048] = {0};
strcpy(temp,head);
char ch;
int fd = open(p_file,O_RDONLY);
if(fd == -1){
perror("open");
exit(EXIT_FAILURE);
}
for(int i = 0;read(fd,&ch,1) > 0;i++){
if(ch == '<'){
temp[strlen(head) + i] = '&';
i++;
temp[strlen(head) + i] = 'l';
i++;
temp[strlen(head) + i] = 't';
i++;
temp[strlen(head) + i] = ';';
}
else if(ch == '>'){
temp[strlen(head) + i] = '&';
i++;
temp[strlen(head) + i] = 'g';
i++;
temp[strlen(head) + i] = 't';
i++;
temp[strlen(head) + i] = ';';
}
else
temp[strlen(head) + i] = ch;
}
strcat(temp,tail);
close(fd);
printf("%d\n",strlen(temp));
fd = open("./exchangedCode.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
if(write(fd,temp,strlen(temp)) != strlen(temp)){
printf("something error!!!\n");
exit(EXIT_FAILURE);
}
printf("转换完成\n");
close(fd);
printf("%d\n",strlen(temp));
system("open ./exchangedCode.txt");
}
int main(int argc, char *argv[]){
if (argc != 2){
printf("command error!\n");
exit(1);
}
exchange(argv[1]);
return 0;
} |
|
|