After yesterday’s post, it was time to finally try to handle a blog post and Cooklang recipe in one file. The solution to how to format things was simple: inline the recipe in a Markdown code fence and pre-process it. The file looks like:
--- [yaml frontmatter] --- [markdown intro] ```
cooklang [cooklang recipe]
``` [markdown outro]
The code to do it is ugly and relies on a Regular Expression1, CookCLI to generate some JSON that I use to render a partial during the view render. I didn’t bother building a nice data object, so I’m using a mess of {}.dig
and case / in / else
pattern-matching statements to generate the markup. It does properly handle marking up the recipe with the h-recipe microformat, so that’s a win. See below for Rails partial2.
As you’ll see, the CLI doesn’t handle combining ingredients of the same name to amounts, and it isn’t able to parse ingredient aliases or comments. I’ll probably open an issue on the project’s GitHub repo, but ultimately it looks like the rust tool is the way to go.
Top comments (0)