Back to Top

BWP Syntax Released!

Previous Post:

BWP Syntax Released!

Support for this plugin has been moved to the BWP Community!

My 3rd WordPress plugin, BWP Syntax, has been released! This plugin uses GeSHi, a server-side syntax highlighting library to highlight code syntax in your posts. It is simple, lightweight, and very easy to use with plenty of options to choose.

Features at a glance

  • Load the plugin only when you need it
  • Option to load media files (CSS, JS, etc.) only when needed
  • Built-in hooks for easier customization
  • A lot of options to choose (I bet you don’t need them all!)
  • Preview any snipplet of code to match your preference
  • Possibility to add more languages
  • Parse code within <pre> tag, <code> tag or using shortcode
  • Parse code within comments
  • Editor button to add code
  • Two output methods, Table or Ordered list
  • Style code globally or language-based
  • Toolbar with toggle button and view source button
  • Work with major browsers, including the all time driving-developers-crazy Internet Explorer 6
  • WordPress Multi-site compatible (not tested with WPMU)
  • Actively developed
  • … And more 😀

The current formal version is 1.0.0 (bug fix release: 1.0.5) and you can find detailed information as well as download links on this page: wordpress-plugins/bwp-syntax/

Please report any bugs by posting a comment below. Thank you!

Take Social Sharing to
the Next Level with Monarch!

Take Social Sharing to the Next Level with Monarch!
Print Article Trackback Trackback to this Article   Subscribe to Comments RSS Subscribe to Comments RSS

52 Opinions for BWP Syntax Released!

  1. User's Gravatar
    1
    tiaurus April 8, 2011 at 5:48 pm – Permalink

    This plugin works in the comments?
    This plug-in RSS?
    What shortcodes can I use?

    • User's Gravatar
      2
      OddOneOut April 8, 2011 at 5:54 pm – Permalink

      Hi tiaurus,

      Please post your comment in English, that is the only language I can understand on this blog, thanks :).

      1. This plugin works fine with comments (if you enable such feature).
      2. I don’t think it will work with RSS, because in RSS there is no stylesheet. Of course you can use the inline styles (Theme options) but remember to uncheck this: This plugin will only load if is_singular() returns true, too.
      3. By default you can use [code]your codes[/code] and it will work like using <pre>. More info can be found here.

      If you have any questions or feature requests, please don’t hesitate to post :).

      • User's Gravatar
        3
        tiaurus April 8, 2011 at 6:14 pm – Permalink

        How to specify the language in shortkode?

      • User's Gravatar
        4
        tiaurus April 8, 2011 at 6:16 pm – Permalink

        [code lang="php"]?

        • User's Gravatar
          5
          OddOneOut April 8, 2011 at 6:19 pm – Permalink

          Exactly 🙂 (you will have to enable the shortcode in the option page). You will use [code] only, right? In that case you should disable <pre> parsing to avoid nesting issue.

  2. User's Gravatar
    6
    tiaurus April 8, 2011 at 7:29 pm – Permalink

    The code && is displayed as &&

    • User's Gravatar
      7
      OddOneOut April 8, 2011 at 8:21 pm – Permalink

      Which editor did you use? Do you have a link so I can see it?

      • User's Gravatar
        8
        tiaurus April 8, 2011 at 8:59 pm – Permalink

        http://n-wp.ru/6289
        <?php the_widget('cat_tag_filter','title=&tags_count=1'); ?>

      • User's Gravatar
        9
        tiaurus April 8, 2011 at 9:01 pm – Permalink

        Using the default editor in WordPress.

        • User's Gravatar
          10
          OddOneOut April 8, 2011 at 9:12 pm – Permalink

          I’m contacting you through your email, are you online now?

          • User's Gravatar
            11
            tiaurus April 8, 2011 at 9:34 pm – Permalink

            Google Talk? I do not use Google Talk.

  3. User's Gravatar
    12
    OddOneOut April 8, 2011 at 9:40 pm – Permalink

    I’m on Windows Live now, calling the email you use to post comment here but no response. Please use the contact form to tell me how to get to you directly and I will try to help with your issue ;).

    • User's Gravatar
      13
      tiaurus April 10, 2011 at 5:05 pm – Permalink

      So how to solve this problem?

      • User's Gravatar
        14
        OddOneOut April 10, 2011 at 5:15 pm – Permalink

        Since you are using the Visual Editor, it’s likely that the editor had somehow converted the && character to its entity before the code was parsed. To solve this quickly, please tell me how to get to you through an instant messenger. We will be in a slow pace if we keep discussing the problem here ;).

        • User's Gravatar
          15
          tiaurus April 10, 2011 at 5:22 pm – Permalink

          I do not speak in English, so there is no reason to use IM.
          Please tell us what is wrong in the HTML editor in WordPress? I enter the code into the HTML (not the visual editor!). With other plugins (eg CodeColorer), was no such problem.

          • User's Gravatar
            16
            OddOneOut April 10, 2011 at 5:26 pm – Permalink

            Ahh, I have figured out the bug. 1.0.4 is on its way now. Please wait just a little bit :).

          • User's Gravatar
            17
            OddOneOut April 10, 2011 at 6:09 pm – Permalink

            Version 1.0.4 is now available, you can download it here or simply wait for WordPress to notify in your Dashboard, please let me know if it works for you!

  4. User's Gravatar
    18
    tiaurus April 10, 2011 at 7:18 pm – Permalink

    test

    <?php the_widget('cat_tag_filter','title=&&tags_count=1'); ?>
    • User's Gravatar
      19
      OddOneOut April 10, 2011 at 8:36 pm – Permalink

      I see it working on http://n-wp.ru/6289 now :). Btw, there’s a missing quote in your post, i.e.:

      'button_title' => 'Show posts' - название кнопки фильтра
      'cat_list_label' => 'Show posts from' - сообщение перед фильтром категорий
      'tag_list_label' => 'With tag:'  - сообщение перед фильтром меток
      

      ‘Show posts from – сообщение перед фильтром категорий should be ‘Show posts from – сообщение перед фильтром категорий. That will help you highlight that codeblock correctly.

  5. User's Gravatar
    20
    tiaurus April 16, 2011 at 2:36 pm – Permalink

    I think the plugin does not correctly handle code like

    • User's Gravatar
      21
      OddOneOut April 16, 2011 at 2:39 pm – Permalink

      Hi again,

      What’s wrong with code like that?

      • User's Gravatar
        22
        tiaurus April 16, 2011 at 2:58 pm – Permalink

        In the comments everything is fine, but if such a code to insert into the post, the text of the post, located behind it, is not displayed.

        • User's Gravatar
          23
          OddOneOut April 16, 2011 at 3:02 pm – Permalink

          Do you have a working example or something? I’m unable to reproduce that… You’re welcomed to use the contact form to send me an example if you want.

          • User's Gravatar
            24
            tiaurus April 22, 2011 at 9:07 pm – Permalink

            If you change all pre tags to the shortcode code, the text appears. I have already changed, so has to reproduce the error can not. Once you see again – give an example.

  6. User's Gravatar
    25
    tiaurus April 22, 2011 at 9:04 pm – Permalink

    Detected an error. If you embed the code in the comments, using pre or shortcode code, sometimes inserts an extra space. This code is invalid.
    screenshot1 – dl.dropbox.com/u/2027201/Images/tiaurus-2011-04-22_165351.png
    screenshot2 – dl.dropbox.com/u/2027201/Images/tiaurus-2011-04-22_165506.png

    • User's Gravatar
      26
      OddOneOut April 22, 2011 at 9:17 pm – Permalink

      Yes that’s a known issue, but not caused by BWP Syntax itself. WordPress places that space for admins, for users WordPress will mangle the codes badly. About the shortcode issue, I will look into it again when I have time.

      So, fixes will be in 1.0.5, which is expected to arrive in a week I think. Thanks for the bug report!

      • User's Gravatar
        27
        tiaurus April 22, 2011 at 9:56 pm – Permalink

        Why, then, other plugins (eg SyntaxHighlighter) correctly displays the code, no extra spaces? I think that inserting an extra space – it’s a bug all plug-ins for GeSHi.

        • User's Gravatar
          28
          OddOneOut April 22, 2011 at 10:02 pm – Permalink

          I know, but you can try disabling my plugin, and that space will still appear. SyntaxHighlighter parses codes before they got mangled, BWP Syntax does that after such things happens. See this example:

          <?php // there is no space ?>
          

          I use the same BWP Syntax 1.0.4 for this website, but the reason why a space isn’t appearing is I put a filter in my theme’s functions.php file to ‘normalize’ <?php before WordPress mangles it.

          • User's Gravatar
            29
            tiaurus April 22, 2011 at 10:41 pm – Permalink

            Please tell me the code of your filter to remove the gap? Incidentally, I wrote about your plugin – http://n-wp.ru/6382
            Thank you!

  7. User's Gravatar
    30
    OddOneOut April 22, 2011 at 11:46 pm – Permalink

    What a pleasant surprise! Thanks for that post (although I had to use Google Translate, haha). Anyway, I will send the filter directly to your email. It’s a stupid trick so I don’t want people to know about it, you know ;-).

    • User's Gravatar
      31
      webnik_dk April 27, 2011 at 2:45 am – Permalink

      I have noticed same problem or what you will call it. I fixed it by searching 🙂 Does not work with your plugin out of the box but lets code tag deal with code with no space. There are reasons why this plugin is not over aggressive in trying to work in comments I guess.

      Just posting this if others have same problem and have not thought about searching for solution or may be stumbled over http://konstruktors.com/blog/wordpress/1850-automatically-escape-html-entities-of-code-fragments-in-comments/ 🙂

      • User's Gravatar
        32
        OddOneOut April 27, 2011 at 7:09 pm – Permalink

        Thanks for your contribution webnik_dk!

        Yeah I don’t recommend posting codes in comments, that’s a disadvantage of GeSHi-based highlighting plugin (heck, I enable such feature on my blog, haha…) 1.1.0 will come with new (and exciting) features and of course such bug will be fixed. Stay tuned!

        • User's Gravatar
          33
          webnik_dk April 28, 2011 at 1:24 am – Permalink

          Don’t know about current security situation for WordPress but script have had problems in the past. May be this back catalog of problems is part of why letting “everyone” post php code is NOT the way to go 😉 For individual sites admin take responsibility but may be not wise if WordPress were open for code snippets out of the box. Releasing a bot which take advantage of an invitation to enter all WordPress sites worldwide will be a highlight of many a hackers career 😉

  8. User's Gravatar
    34
    tiaurus May 3, 2011 at 12:10 am – Permalink

    I put this code in the post with shordcode code – the contents of the post is no longer displayed:

    [code lang="php"]
    <?php
    global $wp_query;
    $max_page = $wp_query->max_num_pages;
    $nump=2;  /*Количество отображаемых подряд номеров страниц*/
     
    if($max_page>1){
    	$paged = intval(get_query_var('paged'));
    	if(empty($paged) || $paged == 0) $paged = 1;
     
    	echo '';
    /*	echo 'Страница '.$paged.' из '.$max_page.'      ';*/
    	if($paged!=1) echo '1 ';
    		else echo '1';
     
    	if($paged-$nump>1) $start=$paged-$nump; else $start=2;
    	if($paged+$nump2) echo "...";
     
    	for ($i=$start;$i<=$end;$i++)
    	 {
    	 if($paged!=$i) echo ''.$i.' ';
    		else echo ''.$i.'';
    	 }
     
    	if($end<$max_page-1) echo "...";
     
    	if($paged!=$max_page) echo ' Последняя »';
    		else echo ' Последняя ';
     
    	echo ''	;
    	}
    ?>
    [/code]
    

    (edited so your comment looks better!)

    • User's Gravatar
      35
      OddOneOut May 3, 2011 at 9:02 am – Permalink

      Hi,

      Thanks for the bug report, I will release a fix as soon as possible.

  9. User's Gravatar
    36
    zeaks June 6, 2011 at 5:04 am – Permalink

    Thanks for this plugin, it seems lightweight and it’s been working very well for me. I recently switched from Syntax Highlighter Evolved. My site contains alot of code snippets, and I though I’d contribute a bit back.

    Since I used a different plugin before this, I used the [ code ] shortcodes throughout my site. Although there is an option to continue using this, I wanted my entire site use the same shortcode, including comments. Using phpmyadmin, this is how I did it http://pastebin.com/wsG8SKfz

    Make sure to backup your database first. Hope someone finds this helpful.

    • User's Gravatar
      37
      OddOneOut June 6, 2011 at 8:38 am – Permalink

      Hi Zeaks!

      Thank you a lot for your contribution, I will surely add the small guide you wrote to the documentation, soon. And about the [code] shortcode, since its drawback is rather clear, I’m glad that you decide to switch to HTML tags :).

      BWP Syntax will be improved greatly in the next major release (1.1.0), so I hope that it can still satisfy you until that very moment.

      Btw, do you need help with styling? The ordered list is somehow uneasy to style so just tell me if you need my assistance (for free, of course!).

  10. User's Gravatar
    38
    zeaks June 6, 2011 at 11:43 am – Permalink

    Thanks. I’m using the unordered list, it looks fine to me in firefox, IE and chrome, unless I’m not seeing something I think it’s great the way it is, but if you have any advice on making them look even better, I’d be happy to try it.

    I’m looking forward to the new version, I post alot of code on my site and it’s nice to have a plugin like this.

    • User's Gravatar
      39
      OddOneOut June 6, 2011 at 4:26 pm – Permalink

      Actually, it’s a matter of your personal interest, so if you think it’s great the way it is, I also think it’s great the way it is :). Anyway, whenever you need to change the styles and find it difficult to do so, feel free to contact me, I will get back to you as fast as I can. Enjoy and stay tuned!

  11. User's Gravatar
    40
    Zeaks June 23, 2011 at 1:38 am – Permalink

    I’m having a strange issue with a post in my comments. It’s auto closing the div tags in the code I posted. you can see the comment here http://zeaks.org/different-sidebar-layout-for-posts-with-twentyten-options/#comment-13154 and what I’ve actually posted in the editor here
    http://screensnapr.com/v/w2Preh.png

    • User's Gravatar
      41
      OddOneOut June 23, 2011 at 9:15 am – Permalink

      Yes that’s the very issue when you post HTML in comments.

      Since my plugin parses codes after it is formatted by WordPress, chances are WordPress has auto corrected your comment’s contents before BWP Syntax does its job.

      To work around this, just convert all the tags to theirs html entities, e.g. &lt;div&gt;. In the next version you won’t have to do this :).

      • User's Gravatar
        42
        Zeaks June 23, 2011 at 10:31 pm – Permalink

        Thanks, I’ll try that. Looking forward to the new version 🙂

  12. User's Gravatar
    43
    tiaurus June 24, 2011 at 3:34 pm – Permalink

    Plugin sometimes does not work properly: if the code inserts a normal user (not administrator), then the code is inserted incorrectly.

    For example, if the subscriber, is using pre, try to insert to the comment code

    <?php global $current_user;
          get_currentuserinfo();
    
          echo 'Username: ' . $current_user->user_login . "\n";
          echo 'User email: ' . $current_user->user_email . "\n";
          echo 'User first name: ' . $current_user->user_firstname . "\n";
          echo 'User last name: ' . $current_user->user_lastname . "\n";
          echo 'User display name: ' . $current_user->display_name . "\n";
          echo 'User ID: ' . $current_user->ID . "\n";
    ?>
    

    then receive:

    user_login . "\n";
          echo 'User email: ' . $current_user->user_email . "\n";
          echo 'User first name: ' . $current_user->user_firstname . "\n";
          echo 'User last name: ' . $current_user->user_lastname . "\n";
          echo 'User display name: ' . $current_user->display_name . "\n";
          echo 'User ID: ' . $current_user->ID . "\n";
    ?>
    

    video: http://www.screenr.com/7qHs
    How to avoid cutting the code?

    • User's Gravatar
      44
      tiaurus June 24, 2011 at 6:01 pm – Permalink

      Made a patch to the code is not cut off.

      For comments:

      add_filter('pre_comment_content', 'encode_code_in_comment');
      function encode_code_in_comment($source) {
        $encoded = preg_replace_callback('/<raw>(.*?)<\/raw>/ims',
        create_function(
          '$matches',
          '$matches[1] = preg_replace(
              array("/^[\r|\n]+/i", "/[\r|\n]+$/i"), "",
              $matches[1]);
            return "<raw>" . htmlentities($matches[1]) . "</raw>";'
        ),
        $source);
        if ($encoded)
          return $encoded;
        else
          return $source;
      }
      

      For the post:

      add_filter('pre_post_content', 'encode_code_in_post');
      function encode_code_in_post($source) {
        $encoded = preg_replace_callback('/<raw>(.*?)<\/raw>/ims',
        create_function(
          '$matches',
          '$matches[1] = preg_replace(
              array("/^[\r|\n]+/i", "/[\r|\n]+$/i"), "",
              $matches[1]);
            return "<raw>" . htmlentities($matches[1]) . "</raw>";'
        ),
        $source);
        if ($encoded)
          return $encoded;
        else
          return $source;
      }
      

      Use: <pre><raw>code</raw></pre>

      But I would like to have subscribers also had the opportunity to embed the code without a loss.

      • User's Gravatar
        45
        OddOneOut June 25, 2011 at 4:33 pm – Permalink

        Hey long time no see,

        Are you using an AJAX comment posting plugin?

        • User's Gravatar
          46
          tiaurus June 25, 2011 at 4:44 pm – Permalink

          Yes, but it’s not in it. In the same blog, in comments with ajax, from subscribers code is cut, the administrators are not cut.

          • User's Gravatar
            47
            OddOneOut June 25, 2011 at 4:56 pm – Permalink

            Could you please tell me the name of that comment plugin? I think I need to take a look at it first, thanks. Btw, I think you should not use the above patches because they might cause white page issue (when there are a lot of contents in comments or post contents).

  13. User's Gravatar
    48
    tiaurus June 25, 2011 at 5:01 pm – Permalink

    I use a theme P2 – it inline ajax comments.

  14. User's Gravatar
    49
    tiaurus June 27, 2011 at 11:20 pm – Permalink

    Cutting code contacts to the rights of users – only the editor and the administrator can insert HTML with no filtering. Therefore it is necessary when you insert the code in the pre disable the subscribers filtering HTML. This can make a plug-in User Role Editor. First, we need to setup the rights of subscribers to note the checkbox unfiltered_html.
    Voila:

    http://dl.dropbox.com/u/2027201/Images/tiaurus-2011-06-27_191337.png

  15. User's Gravatar
    50
    scott September 1, 2011 at 12:02 pm – Permalink

    I just installed this again but I’m unable to get it to work in comments which are using [ code ] tags. Any advice?

    • User's Gravatar
      51
      OddOneOut September 1, 2011 at 10:03 pm – Permalink

      Hi Scott,

      The [code] tag is not parsed inside comments, that is by design. I suggest that you read the documentation to understand the reason behind such decision.

      If you or your visitors have used a lot of [code] tags prior to BWP Syntax’s installation, and you insist on using such tag, you will have to add shortcode support to comment_text, and then use add_shortcode to register the code shortcode.

      Hope that helps.

      • User's Gravatar
        52
        zeaks September 2, 2011 at 7:46 am – Permalink

        My users had trouble understanding how to use code in comments, so I added a message to my comment form with this small function. I just added it to my functions.php of my theme. it will display “Wrap code in <pre></pre> tags. in the response form.

        // Add note to comment form
        add_action( 'comment_form', 'code_note' );
        function code_note() {
        ?>
        <?php echo "Wrap code between <pre> </pre> tags."; ?>
        <?php
        }

— Comments are closed.

Next Post: