Posting Code in WordPress: A Rendering Test for Plugins

Most of you can likely ignore this post; it pri­mar­ily exists so that I can eas­ily check whether or not WordPress (or plu­g­ins or what­ever) is prop­erly han­dling code. The source of the code is linked to below if you’re involved at all with WordPress test­ing /​ devel­op­ment. To every­one else, well, thanks for stop­ping by for this one. :-)

Moving right along…

The fol­low­ing is meant to test WordPress’ han­dling of code posted via the Visual Editor.

Instructions

  • Copy the con­tents of example.txt
  • In the Write Post screen of WordPress, switch to the HTML view (required as we are past­ing in direct HTML).
  • Paste the pre­vi­ously copied con­tents into the post.
  • Switch back to the Visual Editor — every­thing should look as it is meant to regard­ing spac­ing, char­ac­ters, and so on.
  • Save the post (pub­lish­ing it is unnec­es­sary) or let it auto-​​save, and then pre­view it.
  • Go down through the exam­ples, check­ing WordPress’ work.

Examples

Basic HTML: <a href="http://example.tld/?foo=1&bar=2">Link's Text</a>
Explanation: Angle brack­ets & amper­sands should be out­put to the browser as encoded enti­ties; sin­gle & dou­ble quotes should not be made curly.

Basic enti­ties: ... -- --- " ' & < >
Explanation: The char­ac­ters should be directly out­put to the browser (or encoded for such out­put, as in the case of the amper­sand). Three dots should not be made into an ellip­sis; dou­ble and triple dashes should not be con­verted into en or em dashes; quotes should not be made curly; amper­sands and angle brack­ets should be encoded to main­tain (X)HTML validity.

Block exam­ple (PRE tag wrap­ping our CODE tag):

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

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

As above in the HTML & enti­ties exam­ples, all quotes and sym­bols should appear prop­erly, as they do when seen via the Visual Editor. In the three blank lines, tabs should be pre­served (2 in the first blank line, then 3, then 2 again). Prior to the final line of char­ac­ters, a tab should be pre­served. Lastly, between each char­ac­ter exam­ple in the final line, four ordi­nary spaces should be preserved.

Finally, here are the exam­ples again marked up using short­codes in order to test such plu­g­ins (if you do not have a [code] short­code enabled, ignore the following:

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

Basic enti­ties: [code]… — — ” ’ & < >[/​code]

Block exam­ple (PRE tag wrap­ping our CODE tag). Caveat: For this final exam­ple, I am not using a [pre] short­code; the Visual Editor does not rec­og­nize text wrapped in [pre] tags as pre­for­mat­ted, and so it strips out line­breaks and tabs. However, the Visual Editor pro­vides an easy enough means of mak­ing text pre­for­mat­ted, 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]
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Posting Code in WordPress: A Rendering Test for Plugins

  1. The B says:

    I want a refund of my 1m 47s.

    plzk­thx.

  2. Rick Beckman says:

    The B:

    TODO:
    * Invent space­time tra­vers­ing vehi­cle.
    * 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 pre­vent­ing his view­ing of this page.
    * Be destroyed by inevitable paradox.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>