Wordpress way of inserting code snippets don't work.

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?

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.

// 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();

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.

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.

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