Posting Code in WordPress: A Rendering Test for Plugins

by Rick Beckman on May 6, 02008

Last modified on May 5, 02009

Most of you can likely ignore this post; it pri­mar­ily exists so that I can eas­ily check whether or not Word­Press (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 Word­Press test­ing / devel­op­ment. To every­one else, well, thanks for stop­ping by for this one. :-)

Mov­ing right along…

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

Instruc­tions

  • Copy the con­tents of example.txt
  • In the Write Post screen of Word­Press, 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 Edi­tor — 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 Word­Press’ work.

Exam­ples

Basic HTML: <a href="http://example.tld/?foo=1&bar=2">Link's Text</a>
Expla­na­tion: 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: ... -- --- " ' & < >
Expla­na­tion: 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 Edi­tor. 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 Edi­tor does not rec­og­nize text wrapped in [pre] tags as pre­for­mat­ted, and so it strips out line­breaks and tabs. How­ever, the Visual Edi­tor 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]

{ 2 voices in the conversation. Speak up! }

The B May 6, 2008 at 20:52

I want a refund of my 1m 47s.

plzkthx.

Rick Beckman May 6, 2008 at 22:33

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

Previous post:

Next post: