SyntaxHighlighter for Movable Type

SyntaxHighlighter for Movable Type allows you to easily post syntax highlighted code all without loosing it’s formatting or making an manual changes on Movable Type 4 powered by SyntaxHighlighter 2.0.

Download

Functions and Limitations

This plugin has the following functions.

  • Added one tempalte tag and two text filters
  • Install SyntaxHighlighter 2.0 to mt-static
  • Use tempate tag instead of includeing css and javascript on html header
  • Write raw source code in entry by using text filter
  • Supported php dynamic publishing!

It also has the following problems oppositely.

  • The entry dosen’t other text filter (ex. rich text editor)
  • It is not supporeted the configuration of the SyntaxHighlighter
  • Required Movable Type 4 (I have tested with 4.2x, 4.3x and 5.0beta)

How to Use

1. Download this plugin and copy to your mt directory.

2. Add MTSyntaxHighlighterInclude tag to “HTML Header” tempates.

mtsyntaxhighlighter_0.1_01en.jpg

The MTSyntaxHighlighterInclude has brush and theme attributes. The brush attribute is required and the theme attribute is optional.

attributeSyntaxHighlighter 2.0
brushas3, csharp, cpp, css, delphi, diff, groovy, jscript, perl, java, php, plain, powershell , python, ruby, scala, sql, vb, xml(Use CSV)
themedefault, django, emacs,fadetogrey,midnight, rdark

3. Create an Entry

Select “SyntaxHighlighter” or “SyntaxHighlighter + Convert Line Breaks” as Format

mtsyntaxhighlighter_0.1_02en.jpg

Write source code as following format:

[code:language]
source code
[/code]

language is supported in Brush aliases.

languageBrush nameFile name
as3,actionscript3ActionScript3shBrushAS3.js
bash, shellBash/shellshBrushBash.js
c-sharp, csharpC#shBrushCSharp.js
cpp, cC++shBrushCpp.js
cssCSSshBrushCss.js
delphi, pas, pascalDelphishBrushDelphi.js
diff, patchDiffshBrushDiff.js
groovyGroovyshBrushGroovy.js
js, jscript, javascriptJavaScriptshBrushJScript.js
javaJavashBrushJava.js
jfx, javafxJavaFXshBrushJava.js
perl, plPerlshBrushPerl.js
phpPHPshBrushPhp.js
plain, textPlain TextshBrushPlain.js
ps, powershellPowerShellshBrushPowerShell.js
py, pythonPythonshBrushPython.js
rails, ror, rubyRubyshBrushRuby.js
scalaScalashBrushScala.js
sqlSQLshBrushSql.js
vb, vbnetVisual BasicshBrushVb.js
xml, xhtml, xslt, html, xhtmlXMLshBrushXml.js

After publishing, the entry is displayed.

mtsyntaxhighlighter_0.1_04.jpg

(When theme attributes is “emacs” )

mtsyntaxhighlighter_0.1_05.jpg

If you have already used the syntaxhighlighter 1.5

The syntaxhighlighter 2.0 changed the target html tag from version 1.5. You have to set “compatible with 1.5″ in settings.

mtsyntaxhighlighter_0.1_07en.jpg

See also: http://alexgorbatchev.com/wiki/SyntaxHighlighter:Upgrading

License

SyntaxHighlighter for Movable Type. Copyright (C) 2009 makoto_kw ( http://www.makotokw.com )

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

SyntaxHighlighter is licenced under LGPL 3. Copyright (C) 2004-2009 Alex Gorbatchev.

SyntaxHighlighter is donationware. If you are using SyntaxHighlighter 2.0 on your site or including it in your product, please donate.

Powered by PukiWiki

16 Comments

  1. Dave Abrahams

    “Download this plugin and copy to your mt directory”

    What, exactly, does “your mt directory” mean? And what does “copy” mean? am I supposed to unzip the contents, or just drop the .zip file in? If the former, do I need to distribute the contents of the mt-static subdirectory into my mt-static directory, etc.? Please be as specific as possible.

    Thank you!

  2. Dave Abrahams

    Looks from what I did that what I really need to do is unzip the file, and then

    rsync -av mt-SyntaxHighlighter*/ /Library/WebServer/MovableType/

    Maybe by “copy” you meant, “in Windows explorer, drag the contents of the .zip file and drop them on your mt directory,” but that strange “directory hierarchy merging” behavior is completely windows-specific.

    …and then, that’s only going to work because my mt-static folder is a subdirectory of what I think is “my mt directory” (/Library/WebServer/MovableType/), which isn’t a foregone conclusion based on the installation instructions I’ve seen out there on the web.

  3. Dave Abrahams

    Okay, this is pretty cool! But what is the markup syntax aside from

    ...

    ? Is it markdown syntax? Do I need to write in HTML aside from the

    ...

    “tags?”

  4. makoto_kw Author

    @Dave Abrahams

    > But what is the markup syntax aside from

    ? Is it markdown syntax? Do I need to write in HTML aside from the

    “tags?”

    Yes…you have to write HTML tag. Unfortunately, Movable Type can’t apply multiple text filters.

  5. Dave Abrahams

    I actually believe I got multiple filters working with the FormatStack plugin. The key is to put Markdown first in the stack, and then indent all the lines in between

    ...

    by at least one space so Markdown treats the block as code. Apparently the “4 spaces or 1 tab” restriction that markdown used to recognize code blocks has been lifted.

  6. makoto_kw Author

    @Dave Abrahams

    Hi, Dave.

    When “SyntaxHighlighter + Convert Line Breaks” is selected, SyntaxHighlighter for MT applies “Convert Line Breaks” text filter and “SyntaxHighlighter” text filter.

    about “Convert Line Breaks”:
    http://www.movabletype.org/documentation/author/text-formatting.html

    I have written code to apply multiple text filters in the plugin :) And I think that I can add “SyntaxHighlighter + Markdown” text filter (If I have much time..)

  7. Dave Abrahams

    Yep, it’s working for me, too. I actually have to put SyntaxHighlighter first in the chain, or HTML cruft gets inserted into the code blocks. I don’t need indents in the code when I do it that way, either.

    Now what I really need is fine-grained control over syntax highlighted code. For example, I’d like certain regions of the code to be presented as bold text. Any idea how?

  8. Dave Cross

    Has the Perl support been given much testing? There’s an obvious bug in Plugin.pm (look at the perl entry in %spbrushlist in tag_sh_include_20 – it has an extra .sh on the end). But even after fixing that, I still can’t get any highlighting.

    What’s the best place to get support for this plugin? Should I just post questions here or do you have a request tracker anywhere? Also, is there a source code repository anywhere?

  9. Abel Braaksma

    Though I’m not from the Movable Type world, people visiting your blog might be interested in other available brushes as well. The most recent version of the Highlighter contains some more brushes, but I compiled a list that contains all the brushes I could find on the internet, which means: many more languages can be supported! Check my list of downloadable syntaxes at UnderMyHat.org, or add this link to your post :)

    – Abel –

  10. Archie Hill

    i host 5 of my blogs on Blogspot and it is really good for beginners. but if you want something with more features, nothing beats wordpress”.”

  11. Douglas

    I’ve just installed this plugin, but there is a problem with SyntaxHighLighter + Convert Line Breaks. You end up with HTML markup being displayed in the code segments. Is there a solution for this?

    Thanks