如何在wordPress中使代码高亮

今天网上折腾了好久,终于把google的这个高亮插件给整上了,下面是SQL语句高亮的效果,不错吧 嘎嘎

SELECT year, product_name, customer_city, SUM(order_amount), COUNT(*)
FROM
  sales_order_fact a
, date_dim b
, product_dim c
, customer_dim d
WHERE
    a.order_date_sk = b.date_sk
AND a.product_sk = c.product_sk
AND a.customer_sk = d.customer_sk
GROUP BY year, product_name, customer_city
ORDER BY year, product_name, customer_city
;


这里贴一下这个插件怎么用的:
1、到GoogleCode下载Syntax Highlighter 【下载】

2、将解压后的文件放到你的博客程序目录下面

3、在Wordpress写文章时,在“HTML编辑”状态下写,将代码用<pre name=”code”  class=”sql”></pre>包起,当然要把sql换成你写的源码的语言名,下面是Syntax Highlighter支持的语言和对应该处语言名可以使用的的写法:

Language Aliases
C++ cpp, c, c++
C# c#, c-sharp, csharp
CSS css
Delphi delphi, pascal
Java java
Java Script js, jscript, javascript
PHP php
Python py, python
Ruby rb, ruby, rails, ror
Sql sql
VB vb, vb.net
XML/HTML xml, html, xhtml, xslt

 

最后大家贴上这一段代码:

<link type=”text/css” rel=”stylesheet” href=”http://www.ahuoo.com/wp-content/dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css”></link>
<script language=”javascript” src=”http://www.ahuoo.com/wp-content/dp.SyntaxHighlighter/Scripts/shCore.js”></script><br />
<script language=”javascript” src=”http://www.ahuoo.com/wp-content/dp.SyntaxHighlighter/Scripts/shBrushSql.js“></script><br />
<script language=”javascript”>
dp.SyntaxHighlighter.ClipboardSwf =’http://www.ahuoo.com/wp-content/dp.SyntaxHighlighter/Scripts/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll(‘code’);
</script>

路径改一哈,shBrushSql.js 是我要调用的SQL脚本高亮,其他语言你得改哈名字哦

按照上面的用法,发现很不爽,晚上对wordPress的编辑器进行了一番改造,终于可以把google的这个玩意完全集成进去了,大家只要稍微改一下wp-includes/js/quicktags.js 这个文件就ok,如有不懂可以call me~~~~~

已有4 条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>