作者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/m.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