I was(am?) Syntaxhighlighter for Movable Type author. I developed it because I never find Alex Gorbatchev Syntaxhighlighter plugin for Movable Type.
I used the Syntaxhighlighter Evolved on WordPress. I have to make it apply to some entries of Movable Type. Then, I developed two plugins work with Syntaxhighlighter Evolved.
1) for Syntaxhighlighter for Movable Type
change Syntaxhighlighter for Movable Type style(code:lang) to Syntaxhighlighter Evolved style(code class="lang")
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Syntaxhighlighter For Movable Type to Evolved | |
Description: Convert 'SyntaxHighlighter for Movable Type' style to SyntaxHighlighter Evolved style | |
Version: 1.0 | |
Author: makoto_kw | |
Author URI: http://www.makotokw.com/ | |
*/ | |
function SyntaxhighlighterForMovableType2Evolved($text) { | |
return preg_replace('/\[code:([\w#+-]+)\]/s','[code lang="$1"]', $text); | |
} | |
add_filter('the_content', 'SyntaxhighlighterForMovableType2Evolved', 6); // SyntaxHighlighter Evolved used 7 |
2) for Legacy style (Syntaxhighlighter 1.5 style)
highlightcode <pre name="code" class="c"></pre>
Syntaxhighlighter Evolved (2.3.6) dose not support legacy style. It needs to ugrade:
http://alexgorbatchev.com/wiki/SyntaxHighlighter:Upgrading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Syntaxhighlighter for Legacy | |
Description: apply code highlight to the Syntaxhighlighter 1.5 style by Syntaxhighlighter Evolved. | |
Version: 1.0 | |
Author: makoto_kw | |
Author URI: http://www.makotokw.com/ | |
*/ | |
function SyntaxhighlighterEvolvedForPlaneHtml($text) { | |
global $SyntaxHighlighter; | |
if (isset($SyntaxHighlighter)) { | |
// Syntaxhighlighter 1.5 style | |
$useLangs = array(); | |
if (preg_match_all('/name="code" class="([\w#-]+)/', $text, $matches)) { | |
$useLangs = array_merge($useLangs, $matches[1]); | |
} | |
if (count($useLangs)) { | |
foreach ($useLangs as $lang) { | |
// Register this brush as used so it's script will be outputted | |
$SyntaxHighlighter->usedbrushes[$SyntaxHighlighter->brushes[$lang]] = true; | |
} | |
$SyntaxHighlighter->useLegacy = true; // hack! | |
} | |
} | |
return $text; | |
} | |
function SyntaxhighlighterLegacyScript() { | |
global $SyntaxHighlighter; | |
if (isset($SyntaxHighlighter) && $SyntaxHighlighter->useLegacy) { | |
?> | |
<script type="text/javascript" src="<?php echo plugins_url('syntaxhighlighter/syntaxhighlighter/scripts/shLegacy.js')?>"></script> | |
<script type="text/javascript"> | |
dp.SyntaxHighlighter.HighlightAll('code'); | |
</script> | |
<?php | |
} | |
} | |
add_filter('the_content', 'SyntaxhighlighterEvolvedForPlaneHtml'); | |
add_filter('wp_footer', 'SyntaxhighlighterLegacyScript', 20); |