• I want to blog about programming, with source code examples. I’ve tried &ltpre&gt (“preserve code formatting”) and it works but it’s not pretty. Then I saw this: https://en.support.wordpress.com/code/posting-source-code/ , where it implies that WordPress already has available shortcodes for displaying source code.

    But when I tried using some of the suggested shortcodes, e.g., [sourcecode language="xml"] or [sourcecode language="xml"] they didn’t seem to do anything at all and the [sourcecode language="xml"] appears literally in the post. Is there something I have to do to enable the sourcecode shortcode?

    Thanks in advance.

Viewing 14 replies - 1 through 14 (of 14 total)
  • Take a look at some of the posts in my site. I use the plugin SyntaxHighlighter Evolved.

    For self hosted installs, check the credits section on that page on WordPress.com

    Thread Starter plnelson

    (@plnelson)

    Take a look at some of the posts in my site. I use the plugin SyntaxHighlighter Evolved.

    I tried it; it worked great for Java but mangled my XML. Here’s a screenshot: https://blog.nelsondev.net/images/SH_Evolved_1.jpg

    So I posted a question to their forum, https://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/ I included some sample XML which I placed between [code]...[/code]‘s as it suggested. And it mangled the display of that XML, too! Not only that, it failed in a different way than in the screenshot, and it failed differently in Firefox and IE.

    Anyway, my original question was about the shortcodes mentioned in https://en.support.wordpress.com/code/posting-source-code/. How do I get that to work?

    BTW, I’m using WP 3.0.1

    Thread Starter plnelson

    (@plnelson)

    For self hosted installs, check the credits section on that page on WordPress.com

    Thanks, but my question is really about the shortcodes mentioned in https://en.support.wordpress.com/code/posting-source-code/.

    Credits

    Alex Gorbatchev’s SyntaxHighlighter
    project was used in the implemention of this feature. If you are a www.remarpro.com user and would like to use this feature on your self-hosted blog, it is available as a plugin.

    ie. it specifically mentions which plugin those shortcodes are based upon, so that should have been your starting point.

    Thread Starter plnelson

    (@plnelson)

    ie. it specifically mentions which plugin those shortcodes are based upon, so that should have been your starting point.

    I don’t want to implement my own shortcode, i.e., I don’t want to reinvent what they’ve already done; I just want to use the shortcodes described in the link. Also, everything is based on Alex’s code – I’ve already installed SyntaxHighligher-Evolved and SyntaxHighlighterPlus which are also based on it, and they include it in their own installs.

    Anyway, I though the comment you quoted was just giving credit to Alex – are you saying that if I install Alex’s plugin the the shortcodes will just automagically work?

    Thread Starter plnelson

    (@plnelson)

    . . . also, the link in the credit doesn’t go to Alex Gorbatchev’s Syntax Highlighter; it goes to SyntaxHighlighterEvolved by someone named “Viper007Bond”. And I already have that installed! That was the one I posted the screenshot of, above.

    So getting back to my original question: what are the steps needed to get the sourcecode shortcode to work?

    Thread Starter plnelson

    (@plnelson)

    If I use the shortcode syntax [sourcecode language="xml"] with SyntaxHighlighterEvolved activated, I get exactly the same output I had in the screenshot above:

    https://blog.nelsondev.net/images/SH_Evolved_1.jpg

    I’m still confused by why the link in the credits points to SytaxHighlighterEvolved instead of SyntaxHighlighter. But I noticed that Viper007Bond’s first name is Alex, so is it the same author?

    Anyway, does anyone actually know what’s going on with the sourcecode shortcode or are we all just speculating?

    This is the result you got from editing post in the Visual Editor. The Visual Editor of WordPress will convert all those special characters to HTML entities. In my opinion, you have two choices: 1. using only the HTML editor (it’s a pain, I know), or 2. when you add a block of code, add it like this (without spaces):
    [code]< pre>--Your code here--</pre >[/code].

    Hope that might help ??

    Thread Starter plnelson

    (@plnelson)

    This is the result you got from editing post in the Visual Editor. The Visual Editor of WordPress will convert all those special characters to HTML entities.

    Nope. I did not edit the post in the Visual editor.

    I only edit my posts in the HTML editor. I have to because I’m using the Preserve Code Formatting plugin, as I mentioned in the OP, and as you note, the Visual Editor plays havoc with stuff like that.

    I really appreciate everyone’s attempts to guess here, but, please let’s stop speculating! My original post was about the sourcecode shortcode described in https://en.support.wordpress.com/code/posting-source-code/. Does anyone actually know what it takes to get that to work properly? (and also why the link in the credit section doesn’t point to what it says it points to)? Which plugin does it really need?

    Thread Starter plnelson

    (@plnelson)

    I Got It Working !!

    . . .
    . . . but I don’t know how.

    I was experimenting around to see if SH-E was interacting with other plugins on my blog so I disabled Preserve Code Formatting. When I did that SyntaxHighlighter Evolved displayed the XML correctly! But I couldn’t leave Preserve Code Formatting disabled because it would break my whole blog – I use it everywhere. So I reactivated it expecting that SH-E would be broken again but it seems to still be working.

    I’ve made a blog entry (with an artificial date so it would be buried in the past) to test/monitor the situation. It recounts the whole sorry tale. Here

    Hi, glad you got it working! I’m sorry about my previous post.

    It was funny that I was going to tell you to try disabling that plugin, because there’s no way SH-E would mangle your code (unless you use the visual editor, which only happens if you use ancient version of SH-E by the way).

    So now when you post a new blog post with SH-E everything’s fine? What kind of html are you using before installing SH-E that you are afraid of losing? Maybe a parse through all post contents might help.

    korven

    (@korven)

    This happened for me too.

    No visual editor involved, in fact, I just imported my blog from WordPress.com via the XML import to a self-hosted blog.

    As soon as I installed SyntaxHighlighter Evolved, all my source code broke and started displaying with HTML entities. Disabling the plugin makes it go back to being normal.

    There is definitely something faulty with the plugin.

    korven

    (@korven)

    On further inspection, it seems that the XML export from WordPress.com replaces characters in [sourcecode] blocks to HTML entities. This is what causes them to be displayed incorrectly.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Shortcodes and source code’ is closed to new replies.