WordPress.org

Ready to get started?Download WordPress

Forums

Shortcodes and source code (15 posts)

  1. plnelson
    Member
    Posted 3 years ago #

    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: http://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.

  2. vtxyzzy
    Member
    Posted 3 years ago #

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

  3. elfin
    Moderator
    Posted 3 years ago #

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

  4. plnelson
    Member
    Posted 3 years ago #

    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: http://blog.nelsondev.net/images/SH_Evolved_1.jpg

    So I posted a question to their forum, http://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 http://en.support.wordpress.com/code/posting-source-code/. How do I get that to work?

    BTW, I'm using WP 3.0.1

  5. plnelson
    Member
    Posted 3 years ago #

    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 http://en.support.wordpress.com/code/posting-source-code/.

  6. elfin
    Moderator
    Posted 3 years ago #

    Credits

    Alex Gorbatchev’s SyntaxHighlighter
    project was used in the implemention of this feature. If you are a WordPress.org 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.

  7. plnelson
    Member
    Posted 3 years ago #

    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?

  8. plnelson
    Member
    Posted 3 years ago #

    . . . 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?

  9. plnelson
    Member
    Posted 3 years ago #

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

    http://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?

  10. Khang Minh
    Member
    Posted 3 years ago #

    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 :)

  11. plnelson
    Member
    Posted 3 years ago #

    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 http://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?

  12. plnelson
    Member
    Posted 3 years ago #

    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

  13. Khang Minh
    Member
    Posted 3 years ago #

    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.

  14. korven
    Member
    Posted 2 years ago #

    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.

  15. korven
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic