<p>” paragraph tag to be inserted causing it to become invalid.
- Using CDATA tags as proposed by some does not prevent the paragraph tags from being inserted when white-lines where used. Once you save your post or page the editor will wrap the code in CDATA tags anyway, but that doesn’t cause any problems.
- HTML tags in strings used in the code caused the tags to be filtered out by the WYSIWYG editor.
So how do you get it to work then without having to install any additional plugins?
- Don’t use empty lines in-between the code lines. It’s annoying to read since it’s all packed together but you can’t avoid the paragraph tags from being inserted any other way.
- To avoid the HTML tags from being removed from the string data you have to break up the HTML tags so the editor’s regular expression matches don’t catch them any more. For example instead of the string ‘
<br />‘ you use
'<' + 'br />'.
- Write and test the code in your favourite editor and browser. Once it works, apply the above changes to your code to make it work in your post or page.
Another option is to put all your code in an include file, include it in your post and simply call the necessary functions. The advantage of this approach is that it makes your code more manageable and easy to update. The annoying part is that all code isn’t safely embedded in your post so you have to maintain an extra file on your server which you might forget when you’re backup things up or switching hosts.
Photo by ruiwen, cc-licensed