Index: trunk/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.php |
— | — | @@ -49,6 +49,7 @@ |
50 | 50 | ); |
51 | 51 | |
52 | 52 | $wgAutoloadClasses['SyntaxHighlight_GeSHi'] = dirname( __FILE__ ) . '/SyntaxHighlight_GeSHi.class.php'; |
| 53 | +$wgHooks['ShowRawCssJs'][] = 'SyntaxHighlight_GeSHi::viewHook'; |
53 | 54 | $wgExtensionFunctions[] = 'efSyntaxHighlight_GeSHiSetup'; |
54 | 55 | |
55 | 56 | /** |
— | — | @@ -57,4 +58,4 @@ |
58 | 59 | function efSyntaxHighlight_GeSHiSetup() { |
59 | 60 | global $wgParser; |
60 | 61 | $wgParser->setHook( 'source', array( 'SyntaxHighlight_GeSHi', 'parserHook' ) ); |
61 | | -} |
| 62 | +} |
\ No newline at end of file |
Index: trunk/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php |
— | — | @@ -69,6 +69,34 @@ |
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
| 73 | + * Hook into Article::view() to provide syntax highlighting for |
| 74 | + * custom CSS and JavaScript pages |
| 75 | + * |
| 76 | + * @param string $text |
| 77 | + * @param Title $title |
| 78 | + * @param OutputPage $output |
| 79 | + * @return bool |
| 80 | + */ |
| 81 | + public static function viewHook( $text, $title, $output ) { |
| 82 | + // Determine the language |
| 83 | + preg_match( '!\.(css|js)$!u', $title->getText(), $matches ); |
| 84 | + $lang = $matches[1] == 'css' ? 'css' : 'javascript'; |
| 85 | + // Attempt to format |
| 86 | + $geshi = self::prepare( $text, $lang ); |
| 87 | + if( $geshi instanceof GeSHi ) { |
| 88 | + $out = $geshi->parse_code(); |
| 89 | + if( !$geshi->error() ) { |
| 90 | + // Done |
| 91 | + $output->addHeadItem( "source-$lang", self::buildHeadItem( $geshi ) ); |
| 92 | + $output->addHtml( "<div dir=\"ltr\">{$out}</div>" ); |
| 93 | + return false; |
| 94 | + } |
| 95 | + } |
| 96 | + // Bottle out |
| 97 | + return true; |
| 98 | + } |
| 99 | + |
| 100 | + /** |
73 | 101 | * Initialise a GeSHi object to format some code, performing |
74 | 102 | * common setup for all our uses of it |
75 | 103 | * |
— | — | @@ -177,4 +205,4 @@ |
178 | 206 | } |
179 | 207 | } |
180 | 208 | |
181 | | -} |
| 209 | +} |
\ No newline at end of file |