How to add semantics to WordPress posts

Browsing the WordPress’ ideas repository I’ve found one that could make WordPress fill the gap between a blog tool and a knowledge base: Structured Blogging.

The fact that it got 60 votes but only 50% stars means two things:

  1. voting people are lazy thinkers
  2. it’s a difficult task at many levels

Nonetheless it’s a good idea because this is and will be for many years to come the blogging era, where millions of authors post content to the Internet. There is no good reason for that content to be unstructured except lazyness and complexity.

Nothing can be done about lazyness but complexity can be substantially reduced. The solution needs:

  • a mechanism for adding XML tags from some dictionary
  • a template system for showing XML content appropiately

On the path to something readily usable (I hope Matt will provide it in WordPress 3.0), a mechanism could be a jQuery plugin for the visual editor, and a template system could be based on Enzymes.

Autocompletion

I think that tinyMCE can be extended by plugins, but I don’t know how to. jQuery itself has an autocompletion plugin that could be used this way. When an author presses a < key, the autocompletion gets triggered and the popup … pops up 🙂

If you have ever used IME (for Japanese for example), you should know what I mean. Options are organized in a hierarchy and you get the most relevant at the top, depending on the few characters already typed. XML dictionaries could be ajaxed and locally cached; they could be plugins that you install into your blog, or be web services too; they could be international standards compliant or be completely custom.

The most-relevant-first feature of the autocompletion popup would be a big help for authors. If I already opened a Tag, then the most relevant options after pressing < could be:

  1. the closing tag for that Tag
  2. any tag that could be inside that Tag (properly sorted if needed)
  3. any root of the cached dictionaries (if possible in Tag)
  4. an option for accessing additional dictionaries (if possible in Tag)

Templates

A PHP template for properly rendering XML content is very easy to write, and Enzymes could be used in the clockwork. In fact an Enzymes feature is the possibility of easily transcluding all the content of a post or a page by means of the special char *

The XML to HTML template can be transformed in an Enzymes template with a couple of PHP instructions, thus allowing you to almost copy and paste already available templates. Then you could apply a solution like this:

  1. write a private post or page with the XML content, using the autocompletion feature described above (say this post is #123)
  2. write a public post or page with the Enzymes statement {[123.* /template.php]} in its content

The post in 1. needs to be private because you don’t want it to appear on the blog as is, and 2. makes the transformation happen. As an added benefit, you can display that semantic content inside of a greater context, and you can transclude it wherever you want in your WordPress blog (as many times as you like).

XML Editors Comparison

I want to browse and edit some XML tagged content: the jQuery API documentation, a 170KB XML file. I’m not interested here in XML language features. I just want to access the content in a tree / grid view and be able to edit it without much effort.
I wandered around the Internet looking for alternatives, and here are my findings.

EditPlus 2.20
editplus1.pngI use to use EditPlus for editing text files, because it loads fast and although it is a basic script editor it has syntax coloring and many interesting features, like search and replace using regular expressions.

I found: shareware (30 USD); no entities rendering; newlines preserved; no pretty format; editing an element’s attributes and content is basic; no tree view; no grid view.

Microsoft Word 2003
microsoftword1.pngThis was just a try I gave to my preferred doc editor. I recently discovered that the HTML output is now considerably better than it was before, with a perfect rendering in Internet Explorer. So I thought that maybe I could find what I was after.

I found: shopware (229 USD); entities rendering; newlines not preserved; cristal clear pretty format (boxed tags); editing an element’s attributes is not practical (via a modal dialog box via the contextual menu); editing an element’s content is very easy; element’s block doesn’t collapse; no tree view; no grid view; structure protected.

Peter’s XML Editor
petersxmleditor1.pngpetersxmleditor2.pngThis is a free piece of software, with some of the features I need, just a bit old-looking.

I found: freeware; entities rendering (only in tree view); newlines preserved (in source and tree view); very good pretty format (bold tags); element’s block doesn’t collapse; tree view available (not related to source view); no children count; presentation of attributes and content is almost practical (both pairs the tree structure, but content is not shown until a text leaf is reached); editing an element’s attributes is not practical (via a modal dialog box via a double-click, within a fixed size layout); editing an element’s content is not practical (via a modal dialog box via a double click, but in an expandable layout); dialog boxes open slower for elements at the end of the tree; no grid view; drag and drop in the tree view is a buggy feature.

EditiX 5.0
editix1.pngThis is a professional looking shareware, with many many features, and a 30 days trial period.

I found: shareware (39 USD for home users); no entities rendering; newlines preserved; good pretty format (contextually highlighted tags); element’s block doesn’t collapse; tree view available (related to source view); children count; presentation of content limited to source view; editing an element’s attributes and content is practical; no grid view; drag and drop in the tree view is available (but something weird can happen, for example a move needs to be undone twice).

Aptana
aptana1.pngThis is a beautiful sofware for developing Javascript programs, highly configurable.

I found: opensource; no entities rendering; newlines preserved; no pretty format; element’s block collapses; tree view available (related to source view, but not from it); no children count; presentation of attributes and content limited to source view; editing an element’s attributes and content is practical; no grid view; no drag and drop in the tree view; Lexeme tooltip very annoying (cannot be disabled).

Altova XMLSpy
altovaxmlspy1.pngaltovaxmlspy2.pngThis is the new XMLSpy Editor, features packed, free to home users.

I found: shopware (399 EUR) / free to home users (licensing via register and activate); no entities rendering; newlines preserved; pretty format available; element’s block doesn’t collapse; no tree view; grid view available (related to source view; not available to home users); children count available; presentation of attributes and content is almost practical (at each level, children are rows of a grid and their attributes and contents are columns); shape of cells is almost practical (can be adapted via a button, but it’s reset to default fixed size when changing view); editing an element’s attributes and content is practical (via a double-click, within an expandable cell); drag and drop in the grid view is available.

Microsoft XML Notepad 2006
microsoftxmlnotepad1.pngmicrosoftxmlnotepad2.pngThe best for what I was after. Free, fast, functional.

I found: freeware; entities rendering; newlines preserved; no source view; tree view available; no children count (what a pity!); presentation of attributes and content is very practical (both pairs the tree structure, and content is shown a step before a text leaf is reached); editing an element’s attributes and content is very practical (via a single-click if selected, within an expandable cell); drag and drop in the tree view is available.