syntaxhighlight
tag to the MediaWiki markup.addScript
etc. $wgResourceModules['ext.GoogleCodePrettify'] = array( 'localBasePath' => dirname(__FILE__), 'remoteExtPath' => 'GoogleCodePrettify', 'styles' => array('google-code-prettify/prettify.css'), 'scripts' => array('google-code-prettify/prettify.js', 'init.js') );
// Register parser hook $wgHooks['ParserFirstCallInit'][] = 'efGoogleCodePrettify_Setup'; /** * Register parser hook */ function efGoogleCodePrettify_Setup( &$parser ) { $parser->setHook('syntaxhighlight', array('GoogleCodePrettify', 'parserHook')); return true; } class GoogleCodePrettify { private static $prettified = false; public static function parserHook($text, $args = array(), $parser) { self::$prettified = true; return "<pre class=\"prettyprint\">$text</pre>"; }
// Register before display hook $wgHooks['BeforePageDisplay'][] = 'GoogleCodePrettify::beforePageDisplay'; # public static function beforePageDisplay(&$wgOut, &$sk) { if (self::$prettified) { $wgOut->addModules('ext.GoogleCodePrettify'); } // Continue return true; }
init.js
script: (function($, window) { $(window.document).ready(function() { window.prettyPrint(); }); })(window.jQuery, window);
Source: https://habr.com/ru/post/130949/
All Articles