SyntaxHighlighter Evolved

Description:

As seen on WordPress.com.

SyntaxHighlighter Evolved allows you to easily post syntax-highlighted code to your site without having to escape the code or anything. It uses the SyntaxHighlighter JavaScript package by Alex Gorbatchev to do the highlighting and supports all of the package’s parameters via shortcode attributes.

For a list of supported languages (most widely used languages are supported), see the WordPress.com support document.

Example Code Output:

Note that there are various different color schemes available.

[php htmlscript=”true” highlight=”12″]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PHP Code Example</title>
</head>
<body>
<h1>PHP Code Example</h1>

<p><?php echo ‘Hello World!’; ?></p>

<p>This line is highlighted.</p>

<div class="foobar">
This is an
example of smart
tabs.
</div>

<p><a href="http://wordpress.org/">WordPress</a></p>
</body>
</html>[/php]

If you prefer, you can hide the line numbering and other UI stuff with the “light” mode, for example:

[code light=”1″][[php light="true"]your code here[/php]][/code]

There are many other parameters and defaults you can control via the Settings page or the shortcode parameters. Full details and instructions are located at the bottom of the Settings page.

Download:

GitHub:

This plugin is available on GitHub. Issues, patches, and pull requests are welcome.

https://github.com/Viper007Bond/syntaxhighlighter

1,818 thoughts on “SyntaxHighlighter Evolved

  1. Pingback: Code Formatting Plugin Updated | Codethink

  2. Pingback: How and why I moved my blog to Amazon EC2 from WordPress.com | Greg's Ramblings

  3. Pingback: How and why I moved my blog to Amazon EC2 from WordPress.com (Adobe Flash Platform Blog)

  4. Pingback: Antonio Fernandes » Blog Archive » SyntaxHighlighter Evolved Theme: Freckle

  5. Pingback: klingt.net[t] – Ohren auf und durch! » Blog Archive » Java Code test - Breakcore, IDM, Jungle, Drill'n'Bass, Dubstep

  6. Pingback: [WordPress??????] SyntaxHighlighter Evolved | littleflag.com

  7. Really like this plugin, but when I’m adding in shortcodes for things like an html sitemap generator ([code] [html-sitemap][/code]) it ends up reformatting it to this: [code][html sort_column="menu_order" language="-sitemap"][/html][/html][/code] Obviously this poses a problem when using shortcodes that may even mention the word html, so is there a way to disable the plugin from running on the admin side so that this doesn’t happen?

    • Try adding this to your theme’s functions.php file:

      [php]add_filter( ‘syntaxhighlighter_shortcodes’, ‘remove_syntaxhighlighter_html_shortcode’ );

      function remove_syntaxhighlighter_html_shortcode( $shortcodes ) {
      unset( $shortcodes[array_search( ‘html’, $shortcodes )] );

      return $shortcodes;
      }[/php]

      That should stop my plugin from registering the [html] shortcode.

      • Rock! That worked perfectly. I had actually gone into the html-sitemap plugin and modified it’s shortcode, but that’s bad practice since at upgrade it would break. So thanks!

        The only bad part is that if I try and add something like [code] [code lang="html"]blahblahblha[/code] [/code] I get this output instead:
        [code][code lang="html"][/code][/code]test[/html][/code]

        So I can’t post html at all. Not a big deal, but I did want to make you aware of it since you seem to take everyone into consideration (and we all appreciate it :).

  8. Since shBrushAppleScript.js exists in syntaxhighlighter/syntaxhighlighter3/scripts , does that mean I would not have to go through the adding a new brush process?

    [applescript]mystuff[/applescript] does not work for me … although [code]mystuff[/code] does.

    Thanks.

  9. Dear,
    I really love you WP plugin but there is a big problem.
    When your plugin is activated, I can’t upgrade WP using the core installer. I get a Fatal Error Out Of Memory.
    When I tried to upgrade after desactivated your plugin, everthing goes well.

    Have you encoutered this problem ? How can we fix it ?

    Best regards,
    BENOIT

  10. There seems to be an issue with processing of code shortcodes in the comments.

    On my site (www.voidtrance.net), I have some comments which have code included with the [code][code][/code] shortcode. However, they are not being displayed like the code sections in the main post.
    In attempting to debug this, I tried disabling all the plugins on installed on my site and only enabling the syntaxhighliter plugin. This did not fix the issue and the comments were still not formatted properly.
    I did some more digging and found out that the method parse_shortcodes_comment changes the comment shortcode from:
    [code]
    [code lang="php"]
    [/code]
    to
    [code lang=”html”]
    <pre class="blush:php; title: ;" title="">
    [/code]
    which seems to be very different from the code generated for the sections in the main post.

    I would appreciate your help with this?

      • Well,

        I just tested this is on brand new test WP installation with absolutely no other plugins and the default theme (Twenty Ten).

        The plugin works in the actual post and does not work in the comments. I am using WP 3.0.5 with the Twenty Ten 1.1 theme it comes with. I also tried the theme that you use (Mystique) and it still does not work.

      • Alex,

        A little more digging has revealed the following information:
        WP 2.9 introduced some functions to deal with unescaped data, in particular wp_kses_data, which are called to sanitize comments. Those functions use an array of HTML elements which are allowed to be present, everything else is removed.
        The problem is that the <pre> element, which the SyntaxHighlighter plugin uses is not in the list of allowed elements. Therefore, that function removed it and replaces it is <p> tags. This results in the JavaScript code not finding any “code” elements and, hence, not adding the needed formatting.

        The wp_kses_data functions in question are located in wp-include/kses.php

  11. Hi Alex.

    I’m using your plugin, but I’m having a problem with WP Mininfy which removes the newlines from code blocks.

    For example
    [php]
    line 1

    line 2

    line 3
    [/php]
    is displayed
    line 1
    line 2
    line 3

    Do you have anu ideea if there is any hack to make them work together?

  12. Alex, thank you for your quick replay.

    If anybody else is interested in using your plugin with WP Minify and has the same problem as I have(the newlines being removed), the solution is to comment one line in wp-minify.php. You can do that by simply clicking edit on the plugin.

    Search for “// get rid of empty lines” and comment the next line:
    $buffer = preg_replace(‘/\s*(\r?\n)(\r?\n)*/’, ‘$1’, $buffer);

    You can see it working here:
    http://sharepoint-snippets.com/connectable-web-parts/

  13. Pingback: MovableType??Wordpress????? | ??

  14. Hi there, Love your plug-in. It works a treat and compared to the others out there it seems the most up to date and most consistent. There is one thing that i wanted to know if it was possible. I want to display my code in RSS feeds with your encoding aswell. Im not sure if its wise but i know of another blog that use WP-Codebox and his displays formatted code in RSS.

    Is this something that can be done with yours?

  15. Pingback: More WordPress Plugins | Yellow Rose Web Design

  16. Pingback: Cómo conseguir resaltado de sintaxis en Wordpress rápidamente | Web de TresTristesTigres

  17. There is any option to use the highlighted code in the text, without migrating to the next line?
    For example, you need to write a php-function in the text within a paragraph.
    Thank you!

  18. Pingback: CoffeeScript brush for SyntaxHighliter « Rod's Useful Box

  19. Why if i use the latest version it dont runs??? I use WordPress 3.0.5.. but your version 2.2.2 RUNS!!

    Why?? you go to fix it?? so.. i use this old version 🙂

  20. Pingback: Show your code in style with SyntaxHighlighter « Justin Case

  21. Pingback: Disable SyntaxHighlighter Evolved Plugin In Twenty Ten Theme | RozaniGhani

  22. Hi, Alex

    I’m using your plug for syntax highlight right now. And it works wonderful. If it could add the control to load specified theme in displaying the code, that would be perfect. I’m not sure my wish could come true or not? Thanks for your effort anyway!

  23. Hi, Alex

    Let’s forget about my previous request. Today, I encountered the problem by highlight my php code with php tag. The update button leads me to the error message as below. And after I debuged for hours and found it caused by the SyntaxHighLighter. Could you take a look what the root cause? Thanks
    [code]
    Forbidden
    You do not have permission to access this document.
    [/code]
    [php]
    function db_query($sql, $silence = 0) {
    global $querynum, $allqueries, $ignore_db_errors;
    //#–Mirror Function Begin–#
    global $config;
    $pack_sql=$sql;
    $command=explode(" ",trim($pack_sql));
    if (strpos("INSERT UPDATE DELETE CREATE ALTER ",strtoupper($command[0]))!==false)
    {

    $db_sess="temp/sql_".md5($pack_sql).".txt";
    $handler=@fopen($db_sess,"w");
    fputs($handler,$pack_sql);
    fclose($handler);
    chmod($db_sess,0644);

    $pack_db_sess=rawurlencode("/".$db_sess);
    $mirror_host=$config[‘mirror’];
    $err_count=0;
    while ($err_count<10)
    {
    $url_handler=@fopen($mirror_host."/mirror.php?db=".$pack_db_sess,"r");
    $buffer="";
    if (is_resource($url_handler))
    {
    while (!feof($url_handler))
    {
    $buffer .= fgets($url_handler, 4096);
    }
    fclose($url_handler);
    if (trim($buffer)=="OK")
    {
    $err_count=10;
    }
    if(trim($buffer)!="OK" && !$silence && !$ignore_db_errors && $err_count==9)
    {
    db_halt("Mirror MySQL Query Error[$buffer]"."{".$mirror_host."/mirror.php?db=".$pack_db_sess."}", $sql);
    $querynum++;
    return $query;
    }
    }
    else
    {
    break;
    }
    $err_count++;
    }
    unlink($db_sess);
    }
    //#–Mirror Function End–#
    $query = mysql_query($sql);
    if(!$query && !$silence && !$ignore_db_errors) {
    db_halt(‘MySQL Query Error’, $sql);
    }
    $querynum++;
    //$allqueries[]=$sql; //For Debug Use Only
    return $query;
    }
    [/php]

  24. I seem to be having a conflict when I load all the brushes and try to use wp-jquery-lightbox plugin. they work together in most browsers but IE decides to pitch a fit. I would just use the shortcode but I’m using another plugin to run my FAQ part of the site that runs though a shortcode but outputs as html, meaning if i load all the brushes and use [html] <pre class="brush: php;">[/html] it works.

    I suppose my question is,can i just maunaully load just the php brush and is this a problem with your plugin or with the lightbox one. you can see my site at http://wpbook.net currently brushes are turned off. If you go to the Docs/FAQ page you’ll see a code block

  25. Okay, so I cheated I added “[php][/php] [/php ]” to the page that needs the php brush loaded this just loads the php brush but adds and empty php line which isn’t a big deal. It seems the conflict with the lightbox in IE is only when both the brushes and the lightbox are being called on the same page.

  26. Pingback: ?????????html??????? | Yii???

  27. Pingback: ?????? ??? ????????? ???? ?? ?????? WordPress | ????????, ????????? ? ????????? ?? ????? Wordpress.

  28. Pingback: ??? ? ????????? ?? ????? ???????. ????? ???. - ShS's Blog

  29. Pingback: Essential Wordpress Plugins | Luigi Vibal || Official Website

  30. Pingback: urgente! plugin wp

  31. Pingback: Allowing Syntax Highlighting in Comments | Chandler's Zen

  32. Pingback: Mike Hewner's Homepage » Blog Archive » New Mike Homepage

  33. Pingback: Popüler Wordpress Eklentileri | OguzEmre.Com

  34. Pingback: ingegno.it - Just another developer weblog

  35. Pingback: SyntaxHighlighter Evolved is broken « Drew Wells

  36. Pingback: WordPress first Steps » ingegno.it - Just another developer weblog

  37. Pingback: WordPress first Steps | ingegno.it

  38. Pingback: WordPress?????[Syntaxhighlighter] | takana_blog

  39. I like this plugin but I have three problems (perhaps not problems of plugin itself but I started with WordPress few days ago):

    XML – generally how to use the plugin with XML and with WordPress editor. I wrote my frist article which contained a lot of XML examples. When I pass XML to Wysiwyg editor it somehow works but I must reformat it several times after saving draft. The problems occure when I switch to HTML editing. Sometimes I lose start tags, sometimes I lose whole code block. Also XML code is not visible in some RSS readers.

    iPhone – neither v2 or v3 works correctly. In v2 it looks like line which fits into displayed area has different height and glutter padding then line which doesn’t. In v3 glutter has different size then code snippet. Perhaps small problem in case of iPhone but big problem in case of iPad.

  40. I just figured one more problem. I wanted to avoid issues with WordPress editor and I used Windows Live Writer 2011. After submitting draft from Live Writer and checking the preview the code looks like:

    [csharp]public void Method()

    <br />{

    <br />    MyTestClass test = new MyTestClass();

    <br />    test.DoSomeComputation();

    <br />}

    <br />[/csharp]

  41. Pingback: ????????? ???? ??????????? SyntaxHighlighter Plus | ????-812

  42. Hi,

    Have been using your plugin for a while and its great but when l activate with latest WP the whole admin section goes white and l cant do anything in admin section. Plugin does work on live site but kills admin section

      • I’m having the same problem as Michael. I installed the PreCode plugin from 58Bits for Windows Live Writer which helps me preformat csharp code, including all the aspx code. However, when published the code showed up on the site without any line numbers or color formating, just a colored background. When I added a [csharp] [/csharp] tag at the bottom of the post, suddenly all the code wrapped in became formated with lines/color. I haven’t figured out what’s causing that strange behavior. I’m thinking of switching to Razor just so I don’t have to deal with formating issues on my blog!

        • I’m having the same problem as Michael. I installed the PreCode plugin from 58Bits for Windows Live Writer which helps me preformat csharp code, including all the aspx code. However, when published the code showed up on the site without any line numbers or color formating, just a colored background. When I added a [code][csharp] [/csharp][/code]
          tag at the bottom of the post, suddenly all the code wrapped in became formatted with lines/color. I haven’t figured out what’s causing that strange behavior. I’m thinking of switching to Razor just so I don’t have to deal with formating issues on my blog!

  43. Pingback: Fosseus.se

  44. Pingback: Top and Best wordpress plugins for software developer blog | Marmoush Virtual Lab

  45. Pingback: syntax highlighting with WordPress: that’s not that! at blog.humaneguitarist.org

  46. Hi Alex,

    I’m thinking about trying your fantastic looking plugin (really, the best looking code presentations I’ve seen) … but am being held back by only two things – 1) WP indicates that the plugin is compatible up to but not including WP 3.1 and 2) there’s a raft of issues reported above in the last few weeks… ARE THEY RELATED?

    And if they are related, is there an update of this plugin in the wings 🙂 ???

    Kind regards,

    Kelly

Comments are closed.