Source Code Formatting

  • Unknown's avatar

    “It’s an option.” How many words do you need? You already said you understood.

    And why do you look for emotional validation in technical help forums? As you’ve noted, you will not find it here.

  • Unknown's avatar

    poppy are you actually running a WP com blog anywhere? Or not?

  • I’ve just deployed an update to the highlighting code, if you’ve been having problems with the formatting edit your post and try again.

  • Unknown's avatar

    Joseph,

    Thanks. I just checked and it seems like the csharp parser is now accepting gt/lt symbols for generics and XML comments (the original poster’s concern).

    However,…
    When using FF, I still have the problem when the lines are longer than the box and the line background (both even/odd rows) appears gray. And the left side’s green line isn’t matching between the code segment and the header display.

    Here’s the csharp code I’ve been using for testing:

    [sourcecode language='csharp']
    /// <summary>
    /// Test
    /// </summary>
    public void IsAssemblyDebug(string fileName)
    {
         Assembly assemb = Assembly.LoadFile(Path.GetFullPath(fileName));
         bool isDebug = false;
         foreach (object att in assemb.GetCustomAttributes(false))
              if (att is DebuggableAttribute)
                   isDebug = true;
         Console.WriteLine("Assembly is {0}.", isDebug ? "debug" : "release");
    }
    /// <summary>
    /// Hello world.
    /// </summary>
    public string HelloWorld()
    {
         List<string> listOfStrings = new List<string>();
         return "Hello World";
     }
    [/sourcecode]
  • Unknown's avatar

    I too see the gray background if the lines are longer than the box, but I don’t see the problem with the green line Jame’s talking about… I’m using Firefox 2.

    BTW James, excellent blog you have there. I’ve bookmarked it.

  • As mentioned in the FAQ entry we use Javascript from the syntaxhighlighter project. For rendering issues I recommend working with them to get updates/fixes in.

  • Unknown's avatar

    Joseph:
    Hey, thanks — works like a charm now. FWIW, I too am having a bit of funkiness with long lines, but I’m using Konqueror so I don’t expect it to really work (surprised that most of my “regular” sites work at all, really…) Strangely, I’m _not_ getting the grayed-out-lines problem that devblog and James are referring too, if that’s any assistance…

  • Unknown's avatar

    For rendering issues I recommend working with them to get updates/fixes in.

    Excuse me Joseph, if I’m missing something here, but how are we supposed to work with them to get updates or fixes if we can’t even use javascript in our blogs? Shouldn’t you guys do that instead?

    To me is like trying to work with the TinyMCE guys to fix those issues in Safari or Opera.

    I’d agree with you if we used this in our own installs of wordpress, but not here.

  • Unknown's avatar

    devblog — I think he means (and correct me if I’m wrong) that they aren’t planning on modifying the syntaxhighlighter code base, and that any issues with the syntax highlighting should be taken up with them so it comes through in the next release (which I’m assuming WP would install when it’s available…). If WP modifies the code, they’d either have to try and introduce those changes to the syntaxhighlighter project (which shouldn’t be difficult), or worry about trying to merge any changes they make with any future releases.

    That’s my guess, at least….

  • You can preserve spacing a couple of different ways. If you are using the visual editor you can wrap your [sourcecode ....][/sourcecode] lines as preformatted. The other option is to just turn off the visual editor.

    I’ve just done another update which includes a fix to issues with backslashes.

    The line wrap issues are different depending on the browser you use, I don’t get line wraps when using Firefox 2, but I do when using IE7.

    mcory1 is correct, development of the code highlighter should be kept at their site. If there are WordPress specific issues (like space preservation and backslashes) then we’ll work on them, if they are syntaxhighlighter specific issues (like how it renders in different browsers), then those should be reported back to the project so that everyone can benefit.

  • Unknown's avatar

    I understand. Thanks for the clarification to both Joseph and Mcory1

  • Unknown's avatar

    Nice job on the source code feature. I’ve started a separate blog on development simple Ruby applications to tinker around with it, but I’m running into one problem. When I create a post using the sourcecode tag and the code has a conditional expression in it, for example

    if (x < y) then

    The code previews correctly, but when I save and continue editing the post the conditional is changed to

    if (x &amp;lt; y) then

    Which is displayed incorrectly when I preview the post. Further saves will expand the conditional to

    if (x &amp;&amp;lt; y) then

    I’ve tried this in Safari and Firefox v2 with the Visual Editor enabled/disabled with the same results.

  • Unknown's avatar

    Try turning off the Rich Text Editor and then writing a new post and repeating the above steps. The enhanced editor gave me lots of problems until I turned it off, but I’m using Live Writer now and haven’t had any problems with it.

    You can turn off the rich text editor under your user profile page.

  • Unknown's avatar

    I did read through all the earlier comments, but that was in the wee hours last night, so hope this isn’t a repeat.

    I noticed that when I go to the code editor and post my code between the sourcecode tags everything works great. However, if I got back and edit any portion of that blog, from the wysiwyg editor or the code editor I lose the leading white space. For me that’s not a problem because I just make sure if I do make changes I use the code editor and then simply repaste the code between the tags. Voila! no problem.

    Don’t know how to resolve the text wrapping problem, but I figure this is not really a problem because anyone really interested in the code can [view plain] [copy to clipboard] or [print] which is a really COOL feature!

  • Unknown's avatar

    James,

    With the Visual (Rich Text) Editor turned off, typing

    if (x < y) then

    Turns into the following when saved

    (Note: Below, the less than symbol actually appears as ampersand lt; It doesn’t render the way that I want to below.)

    if (x < y) then

    On successive saves, it does not get modified further. Now, the strange thing is that when I type in something like

    if (x > y) then

    When that gets saved, the greater than symbol doesn’t get modified into HTML code and saves the way I would like.

  • Unknown's avatar

    I think I have uncovered the problem many of us are having. If you cut-and-paste directly from http://faq.wordpress.com/2007/09/03/how-do-i-post-source-code/ then you get this: [sourcecode language=’css’]…[/sourcecode]

    Notice that there are smart-quotes around css. If you change the smart-quotes to plain old single-quotes (language=’css’) then it works. Someone should probably go and fix the quotes on that page.

    (Now, if only it would preserve my code’s indentation when I go back to edit it later…)

  • Unknown's avatar

    I am having the same problem as sagaciouspines. It seems to just be a problem with the less-than and ampersand signs. If you look at my blog you can see in all the source code blocks both those signs never show up. They are always in the escaped HTML entity form. I have tried both with and without the rich editor. My code is in Ruby, I don’t know if this problem is specific to that or not.

    Any help would be appreciated.

  • Unknown's avatar

    Guys, can anyone solve this problem?! I really enjoy this new feature, but its killing my code…
    When I post with an amperstand without Rich Text Editor, it transforms this amperstand in a visual (seen in the page, not in the page’s source code) HTML entity. Help!

  • Unknown's avatar

    i tried sourcecode with the rich visual editor turned on AND OFF. i got different results each time, and unfortunately, none of them is correct!

    this is what i got with the rich visual editor turned off:

    view plaincopy to clipboardprint
    
       1. <a
       2.
       3. href=�http://www.addthis.com/bookmark.php&amp;url=PasteTheBlogPostUrlHere&amp;title=Paste
       4.
       5. Blog Post Title� title=�Bookmark using any bookmark manager!�
       6.
       7. ><img src=�http://s9.addthis.com/button1-bm.gif�
       8.
       9. width=�125� height=�16� border=�0� alt=�AddThis Social
      10.
      11. Bookmark Button� /></a>

    you can check the test post here:
    http://shongjog.wordpress.com/2007/10/02/sourcecode-test-ve-turned-off/

    is there any way i can get rid of the recurring “interrogative diamonds” in the code?

    —————————————

    and while the the visual editor is turned on i get this:

    view plaincopy to clipboardprint
    
       1. <a
       2.
       3. href="http://shongjog.wordpress.com/wp-admin/%E2%80%9Dhttp://www.addthis.com/bookmark.php&amp;url=PasteTheBlogPostUrlHere&amp;title=Paste"><img
       4.
       5. src="http://shongjog.wordpress.com/wp-admin/%E2%80%9Dhttp://s9.addthis.com/button1-bm.gif%E2%80%9D"
       6.
       7. width="125" height="16" border="0" alt="�AddThis" /></a>

    the post where you can find this result:
    http://shongjog.wordpress.com/2005/10/02/source-code-test/

    ——————————–

    i chose xml as language attribute:
    [sourcecode language='xml']MYCODE[/sourcecode]
    —————————–

    the code i want to display correctly is this:
    <a href=”http://www.addthis.com/bookmark.php&url=PasteTheBlogPostUrlHere&title=Paste Blog Post Title” title=”Bookmark using any bookmark manager!” ><img src=”http://s9.addthis.com/button1-bm.gif” width=”125″ height=”16″ border=”0″ alt=”AddThis Social Bookmark Button” /></a>

    —————————————————-

    thanks in advance for solving my problem :D

  • Unknown's avatar

    also note that in the very first code, there’s this strange french accent sign above a in several places.

    how do i eliminate that also?

  • The topic ‘Source Code Formatting’ is closed to new replies.