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

No Trackbacks

Trackback URL:

15 Comments

  1. May 7th, 2009 02:27 PM | #1

    “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. May 7th, 2009 02:35 PM | #2

    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. May 7th, 2009 03:09 PM | #3

    Okay, this is pretty cool! But what is the markup syntax aside from [code]...[/code]? Is it markdown syntax? Do I need to write in HTML aside from the [code]...[/code] “tags?”

  4. May 7th, 2009 05:12 PM | #4

    @Dave Abrahams

    Sorry. As you know, to copy directory means override(replace) target in Linux and MacOSX, so you have to merge directory.

  5. May 7th, 2009 05:24 PM | #5

    @Dave Abrahams

    > But what is the markup syntax aside from [code]…[/code]? Is it markdown syntax? Do I need to write in HTML aside from the [code]…[/code] “tags?”

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

  6. May 9th, 2009 01:44 PM | #6

    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 [code]...[/code] 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.

  7. May 13th, 2009 11:10 AM | #7

    Can you explain the difference between plain “SyntaxHighlighter” and “SyntaxHighlighter + Convert Line Breaks?”

    Thanks!

  8. May 13th, 2009 11:31 AM | #8

    @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..)

  9. May 14th, 2009 12:40 AM | #9

    Ummm. it seems FormatStack plugin works fine.
    http://labs.makotokw.com/mtdev/en/2009/05/test-formatstack.html

  10. May 21st, 2009 11:42 PM | #10

    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?

  11. May 22nd, 2009 12:53 AM | #11

    @Dave Abrahams

    I think that the plugin should have configuration on next version.
    http://alexgorbatchev.com/wiki/SyntaxHighlighter:Configuration

  12. June 2nd, 2009 10:18 PM | #12

    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?

  13. September 7th, 2009 07:35 PM | #13

    @Dave Cross
    Dave, it looks like here is Trac for this plugin.

    As for Perl support, basic highlighting “works for me”(after I removed the extraneous suffix you mention). But I upgraded SyntaxHighlighter to 2.0.320. See http://tu.wesolek.net/2009/09/perl-test-in-mt.html for the result.

  14. October 2nd, 2009 12:19 AM | #14

    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 –

  15. May 14th, 2010 05:37 PM | #15

    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”.”

Comments