Rosio Pavoris a blog

Towards a better BBCode

Everyone knows BBCode is a pain to work with, and while WordPress supports limited HTML in user comments, it should be obvious HTML is no better. The unnecessary repetition of SGML-based languages and the insistence on the proper nesting of tags makes them all hideous and unnecessarily error-prone. We can do better.
The discussions of learned societies on the subject have been less than satisfactory, so I decided to just implement my own mark-up language, based on the venerable S-expression:

{b This} is {i {u expert} {o mark-up}}.

This will turn into:

This is expert mark-up.

The immediate effect is that nesting problems and text redundancy immediately disappear. The syntax also lends itself to easy function composition:

{b.i.o.u EXPERT}

EXPERT

Finally, for this first version,0 we also support function iteration:

{sup*3 To the moon}{sub*3 and back.}

To the moonand back.

It goes without saying this can be combined with function composition in arbitrarily complex expressions, with the iteration operator having a higher precedence than the function composition operator.

I’ve elected to use curly braces rather than the more typical parentheses, because curly braces barely see any use in natural language, which is where this mark-up would generally be used. If you do need literal curly braces, you can escape them with a backslash (and if you need a literal \{, you can escape your backslash with a backslash).

As a proof of concept, and because I eat my own dog food, I’ve written (and enabled) a WordPress plugin that enables this SexpCode in blog comments. For sanity, iteration doesn’t go beyond *3. Supported tags are b, i, u, s, o, sub, sup, code, spoiler, quote, blockquote, and m. If you want to use it yourself, adding more tags or changing their definitions should be straightforward.
Trying to use an unsupported or empty tag, or having unbalanced braces (except for closing braces at the end), will assume you’re actually trying to post C-like code, and disable SexpCode for your comment.

Ladies and gentlemen, BBCode was our COBOL. This is our Lisp.

Edit: People who want to implement this themselves should be following this document rather than this post.

Edit again: Play with it!

Edit again again: More implementations:

Know of another implementation (SexpCode+ or SexpCode)? Let me know!


0 Future versions of the language are expected to add support for function arguments (for things like url, img, and colour) and the ability to define aliases (for example, {define exp b.i.o.u}, which would let you use a new exp function as if it were b.i.o.u).

Permalink 48 Comments

Incidentally

My blog now supports the use of tripcodes and secure tripcodes by commenters. The tripcode algorithm should be less broken than Shiichan’s while still not really entirely not being broken. The secure tripcode algorithm is crap and probably not portable.

The source for the plugin is here.

(I don’t approve of tripfaggery any more than the next guy. However, I have too much free time.)

Permalink 11 Comments

Simple Footnoter

Time for another quick-and-dirty WordPress plugin.
Since Emiry likes my footnotes, I wrote a plugin that makes making them a bit easier.

Basically, the idea is that you write [1] (where 1 can be any number), and this plugin will replace it with 1. Then, at the bottom of the post (typically, but not necessarily), you write [f1], and it will replace it with 1. If the latter is at the start of a paragraph, it will also make said paragraph of class “footnote”, which you can then define in your CSS file or what have you to have a different style, if you so desire.

You’ll note that the ID of the anchor tag starts with a random number. This is to prevent (or at least make very unlikely) collisions in IDs if more than one post is being displayed at a time, since that breaks things. Ideally, it would use the post slug for that, but if there’s a way to retrieve a post slug from within a filter, I couldn’t find it in the WordPress API in under two minutes.

It’s not awesome, but it works well enough.
The code is here; as always, save that as a .php file, upload to your plugins folder, and activate. If you have suggestions for improvement, let me know.

Permalink 1 Comment