Need help? Check out our Support site, then


Wordpress way of inserting code snippets don't work.

  1. I am trying to post some computer code, namely javascript, as a snippet in a post in my blog. I use [code language="javascript"] code here... [/code] but this does not work. The code shows all in only one really long line. If I mark the code as "pre", the editor opens an extra

     tag that is never closed, therefore, all the rest of the post is displayed like it's a "pre" style. No idea what's happening here... Can anyone show me some effective way that I can insert my code snippets?

    The blog I need help with is tiagodev.wordpress.com.

  2. You cannot configure the code using a pre-tag. The only configuration parameters you can use is here: http://en.support.wordpress.com/code/posting-source-code/#configuration-parameters

    The doesn't seem to be an option to restrict line length for posted code, so the only way to do that I can think of is to manually press return to break up the lines of code.

  3. No, I did not use pre as a configuration parameter. I wrapped the code-tag with a pre-tag. That was the only way to force my code to not be one-lined.

    If I press return to break up the lines of code, the code is still displayed in only one line but full of br-tags and p-tags. I don't get it.

  4. If possible (i.e. the code isn't confidential or something), please paste the code as it appears in your text editor here. Paste it between backticks, otherwise the software will try to render it or strip it out and we won't be able to see it.

    It could also be helpful if you can provide a screenshot of what you see in an actual blog post. You can't post a screenshot directly in the forum. http://snag.gy/ works well for posting screenshots.

  5. Here is the code:

    // Loop through some items
      items.forEach(function(item){
    
       //Now write each of this items to the disk (I/O here)
         item.saveAsync();
      });
      // This function is meant to be called once all the async
      // calls above are done, but we don't know if/when they are,
      // and therein lies the problem with this approach
      calculateStatsAfterSaving();

    And here is the screenshot:
    http://snag.gy/jSmTc.jpg

    Thanks!

  6. Thanks for providing that info. I've tagged this thread for staff to follow up. Someone else might also answer in the meantime, but please be patient while waiting for a response.

  7. Hi there,

    Could you let me know the exact steps you take to write and post that code snippet? For example, do you write the code in another editor and copy/paste it into your post, or do you write it directly in the post editor at WordPress.com? Do you add the code to your post using the Visual or Text editor? Do you ever switch back and forth between the Visual and Text editors while writing the post?

    You should be able to display your code on multiple lines (and not end up with HTML instead of real line breaks), but more details would help me figure out where things are going wrong.

  8. Could you let me know the exact steps you take to write and post that code snippet?

    I write the code in Sublime text because I was testing it there. Then I copy/paste it to LibreOffice Writer (kinda of a Ubuntu's Office Word). And then I copy/paste again into the Visual editor. After trying for a long time to make it work using the Visual, I tried the Text editor. And then when I got desperate used them back and forth. One thing I did not try though: try to write in the editor from scratch.

  9. Thanks for those details! When you copy/paste from LibreOffice into the Visual editor, do you use the Paste as Text button? If not, it's possible the HTML line break and paragraph tags are being added in at that point.

    I'd recommend giving that a try to see if that works for you. (It's better than having to retype the code from scratch in the editor here if you've already written it in Sublime.)

    If you continue to have trouble with it, let me know and I'll keep investigating. :)

  10. The HTML line breaks and paragraphs seem to be added anyway. No matter what I do. I even tried to write from scratch now and still... nothing!

  11. Sorry about that! I think I pinpointed the issue you're running into — I reported that to our developers so they can take a look. I'll let you know once I have an update from them.

    If there's anything I can help with in the meantime, please let me know.

  12. Hi there,

    Our team fixed up the issue that was adding those HTML tags to the code in your posts. Can you try adding those code snippets again and let me know how it goes?

    Thanks again for reporting the issue!

Topic Closed

This topic has been closed to new replies.

About this Topic