作者descent (「雄辩是银,沉默是金」)
看板Soft_Job
标题Re: [心得] 写blog的好处
时间Tue Mar 28 21:06:38 2017
感谢几位网友们的分享。
这边补上几个资讯
blog2bbs:
http://blog2bbs.herokuapp.com/
这是一个把 blog 文章转成 bbs 的文字格式, 会帮忙把 url, 图档缩网址。
我都是用这方式把 blog 文章贴到 bbs。
效果很好, 连程式码行号都一并留了下来。
贴上程式码, 我是用以下的方式来做, 不依赖任何 blog 提供的功能。
有行号, 语法颜色。
行号是最重要的, 要不然怎麽引用程式码的第几行或是说明该段程式码。
以下的文章就是用
http://blog2bbs.herokuapp.com/ 转出来贴到 bbs 上的。
blog 原文
http://descent-incoming.blogspot.tw/2011/09/source-code-to-html.html
再来是怎麽保存 blog 文章, 我是用 git 存起这些文章, 再贴到 blog 上的,
虽然很麻烦, 但有了版本资讯其实很值得, 也不用怕 blog 平台倒站後,
辛苦写的文章就成孤儿了。
github blog 来得太慢了, 我已经累积大量文章, 不想转换 blog 平台。
而存在 git repository 上, 其实也蛮好的。
----------------- 贴上程式码的文章 bbs 版本 ---------------------
在 blog 贴上程式码 (source code ex: c/c++/组合语言), 需要先将程式码转成 html
语法, 没想到花费的力气比我想像中的大, google 好几天, 不是太复杂 (要修改一堆
css/js ) 就是不合我用。我只需要行号和语法颜色。当然, 最好能在 linux 下使用。
code2html
vi 的 :TOhtml
http://www.opinionatedgeek.com/DotNet/Tools/HTMLEncode/Encode.aspx (
https://goo.gl/klBr3 )
http://blog.xuite.net/givemepassxd/blog/40467229 (
https://goo.gl/6nsqxc )
http://fly2sky999.blogspot.tw/2012/03/blogger-css-block-google-code-prettify.html
(
https://goo.gl/7kHhls )
最後选了 code2html (用 apt-get install code2html 轻松搞定)
code2html -H -n -l as 5M_mem_rw.S > 5M_mem_rw.html
code2html -H -n -l c k.c > k.html
用这些 option 出来的结果前後加上
<pre>
</pre>
即可贴到网页/blog 上。
以下是我用的 pre 有边框的效果。
<pre style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto;
width: 600px; text-align: left;">
</pre>
支援的语言:
descent@ubuntu:1.5$ code2html --mode
Defined modes: ada, ada95, awk, c, c++, cc, cpp, cxx, gpasm, groff, html,
java,
javascript, js, lisp, m4, make, makefile, pas, pascal, patch, perl, plain,
pov,
povray, python, ruby, sh, shellscript, sql.
Defined outputformats: html, html-dark, html-fntlck, html-light, html-nobg,
html-nocolor, html-simple.
方便的 script
h.sh
1 (
https://goo.gl/aEv1OE ) #!/bin/sh
2 (
https://goo.gl/42cR8Z )
3 (
https://goo.gl/ZjMW15 ) echo "<fieldset><legend>$1</legend>" > $1.html
4 (
https://goo.gl/X5nkhQ ) code2html -H -n -l $2 $1 >> $1.html
5 (
https://goo.gl/xKtrWh ) echo "</fieldset>" >> $1.html
组合语言
./h.sh 5M_mem_rw_mix_c.S gpasm
c 语言
./h.sh k.c c
清除 number link: blogger 会填上 link 的内容, 所以把 a tag 换成 b tag, 使用
sed_cmd 来处理即可。
link
1 (
https://goo.gl/aEv1OE ) <a href="" name="line9"> 9</a> xor %eax,
%eax
2 (
https://goo.gl/42cR8Z ) <b> 9</b> xor %eax, %eax
sed_cmd
1 (
https://goo.gl/aEv1OE ) sed -i -e 's/<\/a>/<\/b>/g' simple_proc.S.html
2 (
https://goo.gl/42cR8Z ) sed -i -e 's/<a name="line[0-9]*">/<b>/g'
simple_proc.S.html
加上 sed 的版本
h.sh
1 #!/bin/sh
2 # use code2html to generate html for blog.
3 # language:
4 # ada, ada95, awk, c, c++, cc, cpp, cxx, gpasm, groff, html, java,
5 # javascript, js, lisp, m4, make, makefile, pas, pascal, patch, perl,
plain, pov,
6 # povray, python, ruby, sh, shellscript, sql.
7
8 if [ "$1" == "" ]; then
9 echo "usage: $0 code_filename language"
10 echo "code2html support language syntax"
11 code2html --mode
12 exit 0
13 #else
14 # echo 'usage: code_filename $1'
15 fi
16 L=plain
17
18 if [ "$2" == "" ]; then
19 echo "language syntax: $L"
20 else
21 L=$2
22 fi
23
24
25 echo "<fieldset><legend>$1</legend>" > $1.html
26 echo '<pre style="white-space: pre-wrap;">' >> $1.html
27 code2html -H -n -l $L $1 >> $1.html
28
#code2html -H -N -l $L $1 >> $1.html
29 echo "</pre>" >> $1.html
30 echo "</fieldset>" >> $1.html
31
32 sed -i -e 's/<\/a>/<\/b>/g' $1.html
33 sed -i -e 's/<a name="line[0-9]*">/<b>/g' $1.html
34
35 echo "generate $1.html"
组合语言和 C 语言的效果:
http://descent-incoming.blogspot.tw/2012/05/0-hello-xyz.html (
https://goo.gl/Ak3qyt )
// 本文使用 Blog2BBS 自动将Blog文章转成缩址的BBS纯文字
http://goo.gl/TZ4E17 //
--
纸上得来终觉浅,绝知此事要躬行。
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 117.19.165.194
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Soft_Job/M.1490706405.A.5DA.html
1F:推 landlord: 威!拜倒 03/28 21:21
2F:推 sivid: 猛 03/28 21:52
3F:推 kenshin528: 这一系列钓出好多大大 03/28 22:17
4F:推 vn509942: 赞 03/28 22:53
5F:推 cutekid: 大推(Y) 03/28 23:51
6F:推 iman00b: 还没看文章,纯推这个ID。 03/29 09:29
7F:推 Ekmund: push 03/29 12:50