New Project: Shortcodes
One thing leads to another. I wanted to learn a new language and chose Crystal. To practice, I rewrote my standard practice project, Nicoletta, a static site generator.
That brought to mind doit a task/dataflow library, which made me want to implement something similar, so I wrote Croupier which went well, so I said "Why not write a more serious SSG, which is Nicolino which I think would not be complete without a feature from Nikola which I stole from Hugo, called shortcodes. So I had to write a shortcode parser.
What are shortcodes?
Sort of macros for markdown. You want to do a <figure>
but
markdown doesn't have it, so you do this:
{{% figure src="http://whatever" %}}
And you end up with a figure tag in your document.
That is done by passing data like that "src" argument and the context of the document you are writing into a template, which renders a piece of HTML, that's inserted where the shortcode was and bob's your uncle.
There are variants, and details, and subtleties, but that's the basic idea.
The bad news was that I was not the author of Nikola's current shortcode parser, that was someone else, and I really don't understant their code.
So I wanted to write it from scratch.
I have been wanting to learn ragel for a bit, let's say 10 years. It's a thing that takes a finite state machine description in a DSL and turns it into a parser in the language you want.
As long as you want one of the languages it likes, which is not Crystal, so I used it to generate it in C. And wrapped that in Crystal.
So, that's a very long way to say that I wrote a Shortcode parser library that can be used from Crystal and from C, and since it can be used from C, it can be used from pretty much any language.
It doesn't implement the whole shortcode "specification" (which is not a real thing that exists) but it implements the basics.
Now, I just need to use it in Nicolino, and eventually make it better as needed.
BTW: Ragel rocks.