MediaWiki with Google Code Prettify

To add Googles prettify.js for syntax highlighting to MediaWiki follow the instructions below:

  1. Download google code prettify
  2. Rename the containing src folder to code-prettify
  3. Upload the code-prettify folder (not only the content!) to your MediaWiki installation to the folder “skins”.
  4. Edit the file MonoBook.php (if you use another skin, edit the corresponding file) and add the following lines anywhere within the <head>-Element.

    		
    <script type="text/javascript" src="<?php $this->text('stylepath') ?>/code-prettify/prettify.js"></script>
    
  5. Find the <body>-Element. Usually you will find the following line in the opening tag of the <body>-Element:

    <?php if($this->data['body_onload']) { ?> onload="<?php $this->text('body_onload') ?>;"<?php ?>
    

    change it to:

    <?php if($this->data['body_onload']) { ?> onload="<?php $this->text('body_onload') ?>;prettyPrint();"<?php } else { ?> onload="prettyPrint();" <?php } ?>
    

Inspired by Richard Nichols How-to: Add Code Syntax Highlighting to MediaWiki

Leave a Reply

Required fields are marked *.


This site uses Akismet to reduce spam. Learn how your comment data is processed.