准备工作,下载syntaxhighlighter 2.0,解压后,文件夹内文件夹3个,上传至mt静态文件夹static(个人设置不一样,mt-static),准备就绪。
第一步,首先登陆mt,进去模块编辑,找到header模块,点击打开后,我要找到<$mt:var name="html_head"$>: ,在这段文字之后我们添加以下代码:
第二步,编辑footer模块,在结束前,我们添加以下代码:
<script src="/static/Scripts/shCore.js" type="text/javascript"></script>
<script src="/static/Scripts/shLegacy.js" type="text/javascript"></script>
<script src="/static/Scripts/shBrushJScript.js" type="text/javascript"></script>
<script src="/static/Scripts/shBrushBash.js" type="text/javascript"></script>
<script src="/static/Scripts/shBrushCpp.js" type="text/javascript"></script>
<script type="text/javascript">
SyntaxHighlighter.all();
dp.SyntaxHighlighter.HighlightAll('code');
</script>
第三步,如何在文章中显示syntax highlighter的代码
<pre class="c-sharp" name="code">... some code here ... </pre>
<textarea class="c#" name="code" rows="10" cols="60"> ... some code here ... </textarea>
<pre class="brush:js">
alert("Hello world");
</pre>
syntax highlighter高亮显示支持代码种类很多,具体可参考
google project syntax highlighter intro
注意事项 Notice:Escaping XML tagsHow to install the syntax highlighter 2.0 for Movable Type blog
First,download SyntaxHighlighter. Upload all files to your mt-static folder on your server. Next open your Movable Type web administration interface and open up the templates section. Choose the Template Modules filter. Editing the Header template, you should add the following lines right after <$mt:var name="html_head"$>:
After saving the template you should be editing the Footer template and add the following lines right before the tag:
<script src="/static/Scripts/shCore.js" type="text/javascript"></script>
<script src="/static/Scripts/shLegacy.js" type="text/javascript"></script>
<script src="/static/Scripts/shBrushJScript.js" type="text/javascript"></script>
<script src="/static/Scripts/shBrushBash.js" type="text/javascript"></script>
<script src="/static/Scripts/shBrushCpp.js" type="text/javascript"></script>
<script type="text/javascript">
SyntaxHighlighter.all();
dp.SyntaxHighlighter.HighlightAll('code');
</script>
Regarding the <script language="javascript" src="/static/Scripts/shBrushPhp.js"></script> section you need to decide, which languages you want SyntaxHighlighter to display.
How to use the syntax highlighter in your posts
<pre class="c-sharp" name="code">... some code here ... </pre>
<textarea class="c#" name="code" rows="10" cols="60">... some code here ... </textarea>
<pre class="brush:js">
alert("Hello world");
</pre>
SyntaxHighlighter code support

Leave a comment