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).

Changing ISP

I’m thinking about changing my ISP. Hurricane Electric worked fine so far, but I started to care about some things that are simply impossible with this ISP.

  • he.net pros: per month contract, no setup fees, no hidden costs, reselling allowed
  • he.net cons: only one database per account, subdomains not allowed, no PHP 5, no Ruby, very basic admin interface

I thought that lunarpages.com could be a good alternative, but I’m not sure anymore, after carefully reading their site. The price announced is the classic “starting from” which I hate: it refers to the 24 months prepaid contract. For any contract less than 12 months there is a 30 dollars setup fee. And the minimum contract is 3 months. They give you lots of space, but reselling is not allowed. An interesting feature is that they allow adult content, as long as it is legal in California.

bluehost.com has the same pricing structure, even if they say “no hidden costs”. Besides they charge 10 dollars for each domain… They don’t allow any adult content, nor nudity, nor anything related. An interesting feature is that you have to edit lingerie pictures if you can see through!

How to write a safe RegExp for Opera

The PHP recipe for Chili contains a big regular expression (32862 chars) to account for the thousands of PHP functions.

Internet Explorer and Firefox accept such a giant, but Opera does not. No way. It’s a problem at the core level. So the only solution, very simple though, is not to use a literal expression: use new RegExp( "..." ); instead of /.../.

Remember to escape the expression for strings: for my recipe it was very simple because the step only contains a long list of words, between two word boundaries, which need an extra backslash.