Created
December 26, 2009 06:53
-
-
Save makotokw/263869 to your computer and use it in GitHub Desktop.
WordPress Plugin, apply code highlight to the Syntaxhighlighter 1.5 style by Syntaxhighlighter Evolved.
This file contains 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment