Code Highlighter

19th of April, 2006 (Last modified: 20th of April, 2007) Håvard


/*
Plugin Name: Code Highlighter
Version: 1.1
Plugin URI: http://hvassing.com/my-projects/code-highlighter
Description: Highlights any PHP-code that’s wrapped with a code-element.
Author: Håvard Hvassing
Author URI: http://hvassing.com
*/

This plugin highlights and colour-codes all PHP-code in a post given that the PHP-code is wrapped in a code-element. This allows for easy interpretation of code that’s included in a WordPress post as it uses the standard PHP colours for highlighting. The plugin only highlights text that’s enclosed in a code-element and that includes a <?php-tag.
E.g.:
<code>[php] /* This is a test comment */ [/php]</code>
<?php  /* This is a test comment */ ?>
<code>< ?php /* This is a test comment */ ?></code>
<?php  /* This is a test comment */ ?>

To install the plugin simply upload it to your wp-content/plugin-directory and activate it from the WordPress administration.

Thanks to Scott Merrill for feedback and comments during development. There is also a blog post explaining how this plugin came about; http://hvassing.com/2006/code-highlighter-plugin/

Version 1.1 (Current)

  • Fixed bug: Added unserialize when usingCSS class-names for colour coding

Version 1.0

  • Added support for custom CSS class-names
  • Added support for BBCode-style <?php and [/php], which is translated into <?php and ?>
  • Added support for turning off colour-coding by the user (?highlight=no)

Version: 0.7

  • Fixed bug: Missing argument in <?php  function highlight($code) ?> , $code is now initialized to nothing.

Version: 0.6

  • Highlights code that wraps over several lines
  • Improved efficiency with initial check to see whether or not the plugin is needed
  • Removes additional <?php
  • Cleans up WordPress separation of <?php
  • Added additional comments

Note:
Previous changes are excluded as they are of minor importance to the plugin.

Download

In the future (ToDo)

  • Check that all elements balance

4 Responses to “Code Highlighter”

  1. Hello,

    Thanks for this plugin.

    I’m using Wordpress MU with Dean’s FCKEditor For Wordpress

    if I put :


     
    <?php 
    /* This is a test comment */
     
    echo &#8220;Hello&#8221;;
    ?>


    i get :

    What is the solution to keep the quotes ?

    Thanks a lot.

    1
  1. 1 Blogging Pro China » Blog Archive » WordPress Plugin: Code Highlighter
  2. 2 WP Plugins DB » Plugin Details » Code Highlighter
  3. 3 tilo schröder » WordPress-Plugins » Meine verwendeten WP-Plugins

Leave a Reply




XHTML: You can use these tags <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> :
If you want to include PHP-code you can do so by writing <code>[php]my_function()</code>

Related

Back to My Projects