前两天才在自己机器上装的,本来是为了方便在本机上写离线博客然后合适的时候再发到公网上的。感觉靠谱,好用,比我用的很多公共博客都靠谱。不排除过段日子直接买空间搞个mjxian.net之类的个人博客,哈哈……
主题用的是wp-googlechrome,界面上作了少许定制和优化。同时对写作时插入代码如何支持语法高亮等部分进行了更一些感觉更易用的优化。
2008-12-23
在fckeditor for wordpress样式菜单中使用wp-syntax插件
wp-syntax是wp的语法高亮插件,支持包括了c、python、sql、shell、diff等等在内的大多数程序语法格式,它使用特殊的xml语句对字符串进行对应程序语言的格式化。可以在这里下载。
--- fckeditor-for-wordpress-plugin/fckeditor/fckstyles.xml 2008-04-24 09:54:16.000000000 +0800
+++ /var/www/wordpress/wp-content/plugins/fckeditor-for-wordpress-plugin/fckeditor/fckstyles.xml 2008-12-23 00:40:59.000000000 +0800
@@ -60,6 +60,74 @@
<Style name="Subscript" element="sub" />
<Style name="Superscript" element="sup" />
-->
+ <Style name="Computer Code" element="div">
+ <Attribute name="class" value="cuscode" />
+ </Style>
+
+ <Style name="C" element="pre">
+ <Attribute name="lang" value="cpp" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="shell" element="pre">
+ <Attribute name="lang" value="bash" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="diff" element="pre">
+ <Attribute name="lang" value="diff" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="python" element="pre">
+ <Attribute name="lang" value="python" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="perl" element="pre">
+ <Attribute name="lang" value="perl" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="php" element="pre">
+ <Attribute name="lang" value="php" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="xml" element="pre">
+ <Attribute name="lang" value="xml" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="javascript" element="pre">
+ <Attribute name="lang" value="javascript" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="css" element="pre">
+ <Attribute name="lang" value="css" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="sql" element="pre">
+ <Attribute name="lang" value="sql" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="java" element="pre">
+ <Attribute name="lang" value="java" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="ruby" element="pre">
+ <Attribute name="lang" value="ruby" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="php" element="pre">
+ <Attribute name="lang" value="php" />
+ <Attribute name="line" value="1" />
+ </Style>
<Style name="Marker: Yellow" element="span">
<Style name="background-color" value="Yellow" />
@@ -72,7 +140,8 @@
<Style name="Small" element="small" />
<Style name="Typewriter" element="tt" />
- <Style name="Computer Code" element="code" />
+ <!-- <Style name="Computer Code" element="code" />-->
+
<Style name="Keyboard Phrase" element="kbd" />
<Style name="Sample Text" element="samp" />
<Style name="Variable" element="var" />
--- wp-syntax/wp-syntax.php 2008-08-24 19:22:16.000000000 +0800
+++ /var/www/wordpress/wp-content/plugins/wp-syntax/wp-syntax.php 2008-12-27 01:05:12.000000000 +0800
@@ -68,6 +68,15 @@
{
global $wp_syntax_token, $wp_syntax_matches;
+ //replace the escape character to origin, which has been replaced
+ //by fckeditor, added by mjxian
+ $match = str_replace("&", "&", $match);
+ $match = str_replace("<", "<", $match); + $match = str_replace(">", ">", $match);
+ $match = str_replace(""", "\"", $match);
+ $match = str_replace(">", ">", $match);
+
+
$i = count($wp_syntax_matches);
$wp_syntax_matches[$i] = $match;
TODO:可能还需要在syntax.php的wp_syntax_after_filter函数中重新把没有按语法格式化的特殊字符替换转义符,但没作也没发现什么问题,估计这块wordpress会自动替换,就不作这个工作了。
fckeditor for wordpress是在wordpress上使用的类微软office界面的所见即所得编辑器插件,同时可以通过修改代码定制自己的工具栏。可以在这里下载。
第一步:通过修改fckeditor的样式表文件,加入wp-syntax支持的语法格式。
wp-content/plugins/fckeditor-for-wordpress-plugin/fckeditor/fckstyles.xml
--- fckeditor-for-wordpress-plugin/fckeditor/fckstyles.xml 2008-04-24 09:54:16.000000000 +0800
+++ /var/www/wordpress/wp-content/plugins/fckeditor-for-wordpress-plugin/fckeditor/fckstyles.xml 2008-12-23 00:40:59.000000000 +0800
@@ -60,6 +60,74 @@
<Style name="Subscript" element="sub" />
<Style name="Superscript" element="sup" />
-->
+ <Style name="Computer Code" element="div">
+ <Attribute name="class" value="cuscode" />
+ </Style>
+
+ <Style name="C" element="pre">
+ <Attribute name="lang" value="cpp" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="shell" element="pre">
+ <Attribute name="lang" value="bash" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="diff" element="pre">
+ <Attribute name="lang" value="diff" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="python" element="pre">
+ <Attribute name="lang" value="python" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="perl" element="pre">
+ <Attribute name="lang" value="perl" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="php" element="pre">
+ <Attribute name="lang" value="php" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="xml" element="pre">
+ <Attribute name="lang" value="xml" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="javascript" element="pre">
+ <Attribute name="lang" value="javascript" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="css" element="pre">
+ <Attribute name="lang" value="css" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="sql" element="pre">
+ <Attribute name="lang" value="sql" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="java" element="pre">
+ <Attribute name="lang" value="java" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="ruby" element="pre">
+ <Attribute name="lang" value="ruby" />
+ <Attribute name="line" value="1" />
+ </Style>
+
+ <Style name="php" element="pre">
+ <Attribute name="lang" value="php" />
+ <Attribute name="line" value="1" />
+ </Style>
<Style name="Marker: Yellow" element="span">
<Style name="background-color" value="Yellow" />
@@ -72,7 +140,8 @@
<Style name="Small" element="small" />
<Style name="Typewriter" element="tt" />
- <Style name="Computer Code" element="code" />
+ <!-- <Style name="Computer Code" element="code" />-->
+
<Style name="Keyboard Phrase" element="kbd" />
<Style name="Sample Text" element="samp" />
<Style name="Variable" element="var" />
第二步、由于fckeditor默认把html的特殊字符进行了转义,而wp-syntax不处理这些转义过的html转义符。所以需要把转义符还原为原始的字符串:
wp-content/plugins/wp-syntax/wp-syntax.php
--- wp-syntax/wp-syntax.php 2008-08-24 19:22:16.000000000 +0800
+++ /var/www/wordpress/wp-content/plugins/wp-syntax/wp-syntax.php 2008-12-27 01:05:12.000000000 +0800
@@ -68,6 +68,15 @@
{
global $wp_syntax_token, $wp_syntax_matches;
+ //replace the escape character to origin, which has been replaced
+ //by fckeditor, added by mjxian
+ $match = str_replace("&", "&", $match);
+ $match = str_replace("<", "<", $match); + $match = str_replace(">", ">", $match);
+ $match = str_replace(""", "\"", $match);
+ $match = str_replace(">", ">", $match);
+
+
$i = count($wp_syntax_matches);
$wp_syntax_matches[$i] = $match;
效果图:
TODO:可能还需要在syntax.php的wp_syntax_after_filter函数中重新把没有按语法格式化的特殊字符替换转义符,但没作也没发现什么问题,估计这块wordpress会自动替换,就不作这个工作了。
2008-12-07
一个索引man手册的脚本
联机手册页manpages是*NIX用户必不可少的参考文档,apropos(1)可以用于查找手册页的名字和介绍;或者通过导入脚本/etc/bash_completion,可以使用制表键的自动补全功能来列出手册页清单。
这里我自己也写了个比较山寨的索引工具来查找man手册。
程序用vim显示匹配的man手册条目列表,移动光标到相应条目,键入回车即可跳转到对应的man命令查看页,键入q退出程序。
用法:
把上面的脚本以manindex为名字保存放到你的PATH中并设置执行属性后,可以在你的vimrc中加入
这样在使用vim时,就可以随时用K查看对应的关键字看都有可供参考的联机手册了。
下图为执行"manindex 7"的结果,它显示了man手册第7章节所能找到的所有条目:
说明:
不完善的地方:
未知章节号时,按默认方式执行man。例如我执行"manindex mkdir"的话,显示的mkdir条目只能跳转到"man mkdir"。而实际上有mkdir(1)和mkdir(2)两个不同章节的条目。以后会提供条目对应的章节。可以选择使用"man 1 mkdir"还是"man 2 mkdir"
这里我自己也写了个比较山寨的索引工具来查找man手册。
#!/bin/bashTMP1="/tmp/manindex1.$$"TMP2="/tmp/manindex2.$$"echo "# Online Reference Manuals Index" >> $TMP1echo "# type Enter to see the manual of entry you selected" >> $TMP1echo "# type q to quit" >> $TMP1SEC=`echo $1 | grep "^[1-9]$"`for DIR in `manpath | sed 's/:/ /g'`;docase $1 in[1-9]) ls $DIR/man$1 2>/dev/null ;;'') ls $DIR/man* | grep -v "/" ;;*) find $DIR -regex .*$1[^$/]+$ -exec basename {} \;;;esac | sed 's/.gz$//g;s/\.[n0-9][a-z]*$//g' >> $TMP2donecat $TMP2 | grep -v '^[\s]*$' | sort | uniq >> $TMP1vim "+syntax on" "+set filetype=conf nonu noma" "+map q :q!" "+map :!man $SEC " $TMP1 rm -f $TMP1 $TMP2
程序用vim显示匹配的man手册条目列表,移动光标到相应条目,键入回车即可跳转到对应的man命令查看页,键入q退出程序。
用法:
manindex [正则表达式 或者 章节号]
把上面的脚本以manindex为名字保存放到你的PATH中并设置执行属性后,可以在你的vimrc中加入
set keywordprg=manindex
这样在使用vim时,就可以随时用K查看对应的关键字看都有可供参考的联机手册了。
下图为执行"manindex 7"的结果,它显示了man手册第7章节所能找到的所有条目:
说明:
- 不带参数直接执行此脚本,显示所有条目;
- 参数为1-9之间的数字,显示系统中对应章节的所有条目;
- 参数为正则表达式,显示匹配的条目(不支持^和$);
不完善的地方:
未知章节号时,按默认方式执行man。例如我执行"manindex mkdir"的话,显示的mkdir条目只能跳转到"man mkdir"。而实际上有mkdir(1)和mkdir(2)两个不同章节的条目。以后会提供条目对应的章节。可以选择使用"man 1 mkdir"还是"man 2 mkdir"
订阅:
博文 (Atom)


