A library to parse shortcodes as used in Hugo and Nikola
Go to file
2023-07-14 17:52:25 -03:00
.vscode meh 2023-07-12 17:30:41 -03:00
spec So the test was wrong :-) 2023-07-14 17:52:25 -03:00
src So the test was wrong :-) 2023-07-14 17:52:25 -03:00
.gitignore It builds again, test fails 2023-07-14 13:49:43 -03:00
LICENSE license 2023-07-14 10:04:01 -03:00
README.md Cleanup 2023-07-14 12:08:11 -03:00
shard.yml Trying to make this work 2023-07-14 11:55:51 -03:00
TODO.md return errors from parse() 2023-07-13 22:05:11 -03:00


What it is

This is a parser for the shortcode spec as explained in the Hugo docs and used in Hugo and Nikola. Approximately.

I am implementing this for Nicolino.

It probably won't be 100% identical, but I'll try to make it as close as practical.

  • Implemented in Ragel + C for performance
  • Allocates no memory, because all strings are references to pieces of input.

What works

  • Detect shortcodes with names
  • Standalone and matched shortcodes
  • Capture data between tags in matched shortcodes
  • Capture arguments with and without names
  • Capture values with and without quotes (with details, see TODO)


You need Ragel and a C compiler.

Ragel is used to generate shortcodes.c out of shortcodes.rl. As a convenience there is a generated shortcodes.c in the repo,


  cd src && make

To run tests:

  crystal spec


  1. Add the dependency to your shard.yml:

        github: ralsina/shortcodes
  2. Run shards install


require "shortcodes"