If you've used WordPress, you may have run across shortcodes. They're little directives you type into the editor box which then evaluate dynamically when the content is rendered on the outside of you site. Plugins can register new shortcode handlers, which are implemented as a simple function callback. It's a really simple way to expose psuedo-programming constructs to content authors in a safe manner (because you as the admin/developer can control which shortcodes are available), and without requiring any PHP knowledge and/or server access.
I needed this sort of functionality in CFML, so after playing with a few different syntaxes and parsers for them, I decided that a direct port of the WordPress shortcodes implementation was the best choice. The code is pretty small (the grammar is context free and the parser is RegEx-based), and the port (including unit tests) took perhaps an hour and a half. I had to roll my own REReplaceCallback UDF to match one of the PHP builtins, as well as change the callback API slightly to deal with CFML idoms, but it's a pretty direct port.
So what can you do with shortcodes? Here's a little demo, both of the front side (the content) and the backside (the handlers and processing). There is also a link to the source, of course. And like all my projects, there is a project page where current project information will always be available.
Looks pretty sweet. I've been digging the Wordpress shortcode functionality and I might need this in a future CF project.
Wordpress is an fantastic CMS with incredible versatility. And ShortCodes are amazing.
Really like your demo of Latex ShortCodes.
If you did a ShortCode for Syntax Highlighting for CFM pages that would be very cool.
ThomasB
Thomas,
Implementing your own shortcode is trivially easy, so if you have a syntax highlighting package (there are several available), it'd be short work to wrap it up in a CFC that the shortcode engine can use. Basically you just need something like this:
Obviously the actual implementation of the method will depend on the highlighting package you selected.