目录

从iG:Syntax Hiliter转换到WP-Syntax

目录

终于决定放弃使用了三年多的iG:Syntax Hiliter,将代码语法高亮插件换成WP-Syntax

原因是Vim的Markdown语法高亮插件有问题,会把iG的标签[LANG]当作Markdown的超链接处理,结果导致插入代码后,后面的内容被错误地著色,很难看。而Syntax使用<pre lang="LANG">格式的标签,不会有这个问题。

其实很早就想过要换了,只是受累于使用iG进行高亮的文章太多,替换起来不方便。加上后来解决了由于iG停止更新导致的不支持更多的语法的问题,所以就一致拖到现在。今天晚上花了一个小时就完成了替换,比想象中的要容易地多。

根据我使用过的语法的情况,使用以下语句在数据库中替换iG的标签到Syntax的标签:

```sql update wp_posts set post_content=replace(post_content,'[bash]','<pre lang="bash" line="1">'); update wp_posts set post_content=replace(post_content,'[/bash]','</pre>'); update wp_posts set post_content=replace(post_content,'[python]','<pre lang="python" line="1">'); update wp_posts set post_content=replace(post_content,'[/python]','</pre>'); update wp_posts set post_content=replace(post_content,'[vim]','<pre lang="vim" line="1">'); update wp_posts set post_content=replace(post_content,'[/vim]','</pre>'); update wp_posts set post_content=replace(post_content,'[java]','<pre lang="java" line="1">'); update wp_posts set post_content=replace(post_content,'[/java]','</pre>'); update wp_posts set post_content=replace(post_content,'[lua]','<pre lang="lua" line="1">'); update wp_posts set post_content=replace(post_content,'[/lua]','</pre>'); update wp_posts set post_content=replace(post_content,'[sql]','<pre lang="sql" line="1">'); update wp_posts set post_content=replace(post_content,'[/sql]','</pre>'); update wp_posts set post_content=replace(post_content,'[plsql]','<pre lang="plsql" line="1">'); update wp_posts set post_content=replace(post_content,'[/plsql]','</pre>'); update wp_posts set post_content=replace(post_content,'[php]','<pre lang="php" line="1">'); update wp_posts set post_content=replace(post_content,'[/php]','</pre>'); update wp_posts set post_content=replace(post_content,'[cpp]','<pre lang="cpp" line="1">'); update wp_posts set post_content=replace(post_content,'[/cpp]','</pre>'); update wp_posts set post_content=replace(post_content,'[inno]','<pre lang="inno" line="1">'); update wp_posts set post_content=replace(post_content,'[/inno]','</pre>'); update wp_posts set post_content=replace(post_content,'[xml]','<pre lang="xml" line="1">'); update wp_posts set post_content=replace(post_content,'[/xml]','</pre>'); update wp_posts set post_content=replace(post_content,'[html]','<pre lang="html4strict" line="1">'); update wp_posts set post_content=replace(post_content,'[/html]','</pre>'); update wp_posts set post_content=replace(post_content,'[ini]','<pre lang="ini" line="1">'); update wp_posts set post_content=replace(post_content,'[/ini]','</pre>'); update wp_posts set post_content=replace(post_content,'[pascal]','<pre lang="pascal" line="1">'); update wp_posts set post_content=replace(post_content,'[/pascal]','</pre>'); update wp_posts set post_content=replace(post_content,'[javascript]','<pre lang="javascript" line="1">'); update wp_posts set post_content=replace(post_content,'[/javascript]','</pre>'); update wp_posts set post_content=replace(post_content,'[reg]','<pre lang="reg" line="1">'); update wp_posts set post_content=replace(post_content,'[/reg]','</pre>'); update wp_posts set post_content=replace(post_content,'[css]','<pre lang="css" line="1">'); update wp_posts set post_content=replace(post_content,'[/css]','</pre>'); update wp_posts set post_content=replace(post_content,'<coolcode LANG="php">','<pre lang="php" line="1">'); update wp_posts set post_content=replace(post_content,'</coolcode>','</pre>'); ```

即便转换到Syntax,也不能避免Vim中Markdown语法高亮的问题,只要文字中出现成对的方括号,仍然会出问题,正确的做法是对HTML标签中的内容不进行Markdown语法的著色。

在转换和写这篇文章的过程中,发现WP-Syntax还存在一些问题,例如启用行号后部分表格不能充满页面宽度的问题,还有上面这些SQL语句,必须将其中的尖括号替换成HTML实体才能正常显示。看来虽然历经两三年的发展,WP-Syntax还是不很成熟。

Posted via UltraBlog.vim.