Posting Code in WordPress: A Rendering Test for Plugins

Most of you can likely ignore this post; it primarily exists so that I can easily check whether or not WordPress (or plugins or whatever) is properly handling code. The source of the code is linked to below if you’re involved at all with WordPress testing / development. To everyone else, well, thanks for stopping by for this one. :-)

Moving right along…

The following is meant to test WordPress’ handling of code posted via the Visual Editor.

Instructions

  • Copy the contents of example.txt
  • In the Write Post screen of WordPress, switch to the HTML view (required as we are pasting in direct HTML).
  • Paste the previously copied contents into the post.
  • Switch back to the Visual Editor — everything should look as it is meant to regarding spacing, characters, and so on.
  • Save the post (publishing it is unnecessary) or let it auto-save, and then preview it.
  • Go down through the examples, checking WordPress’ work.

Examples

Basic HTML: <a href="http://example.tld/?foo=1&bar=2">Link's Text</a>
Explanation: Angle brackets & ampersands should be output to the browser as encoded entities; single & double quotes should not be made curly.

Basic entities: ... -- --- " ' & < >
Explanation: The characters should be directly output to the browser (or encoded for such output, as in the case of the ampersand). Three dots should not be made into an ellipsis; double and triple dashes should not be converted into en or em dashes; quotes should not be made curly; ampersands and angle brackets should be encoded to maintain (X)HTML validity.

Block example (PRE tag wrapping our CODE tag):

<a href="http://example.com/?foo=1&bar=2">Link's Text</a>

	...    --    ---    "    '    &    <    >

As above in the HTML & entities examples, all quotes and symbols should appear properly, as they do when seen via the Visual Editor. In the three blank lines, tabs should be preserved (2 in the first blank line, then 3, then 2 again). Prior to the final line of characters, a tab should be preserved. Lastly, between each character example in the final line, four ordinary spaces should be preserved.

Finally, here are the examples again marked up using shortcodes in order to test such plugins (if you do not have a [code] shortcode enabled, ignore the following:

Basic HTML: [code]<a href=”http://example.tld/?foo=1&bar=2″>Link’s Text</a>[/code]

Basic entities: [code]… — — ” ‘ & < >[/code]

Block example (PRE tag wrapping our CODE tag). Caveat: For this final example, I am not using a [pre] shortcode; the Visual Editor does not recognize text wrapped in [pre] tags as preformatted, and so it strips out linebreaks and tabs. However, the Visual Editor provides an easy enough means of making text preformatted, so I’m using the PRE HTML tag in this final example:

[code]<a href="http://example.tld/?foo=1&bar=2">Link's Text</a>

	...    --    ---    "    '    &    <    >[/code]

2 thoughts on “Posting Code in WordPress: A Rendering Test for Plugins”

  1. The B:

    TODO:
    * Invent spacetime traversing vehicle.
    * Go back in time to circa 8:50 PM, 2008/05/06.
    * Travel to secret Canadian area wherein the agent known only as “The B” will have his future altered, thereby preventing his viewing of this page.
    * Be destroyed by inevitable paradox.

Leave a Comment

Your email address will not be published. Required fields are marked *

Use your Gravatar-enabled email address while commenting to automatically enhance your comment with some of Gravatar's open profile data.

Comments must be made in accordance with the comment policy. This site uses Akismet to reduce spam; learn how your comment data is processed.

You may use Markdown to format your comments; additionally, these HTML tags and attributes may be used: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.

the Rick Beckman archive
Scroll to Top