Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress Plugin, apply code highlight to the Syntaxhighlighter 1.5 style by Syntaxhighlighter Evolved.
<?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