A rock that is able to process markdown files with metadata
You can install it with Luarocks
$ luarocks install lua-markdown-extra
Consider the following markdown file:
<!--
title: My Markdown document with metadata
layout: just a layout
-->
This is my Markdown
# This is a title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate assumenda provident nisi accusamus animi magnam porro id, vel saepe voluptate similique quia quis exercitationem, soluta, error dolorem modi obcaecati. Iusto?
You can process it with markdown_extra.from_file(filePath)
or markdown_extra.from_string(stringContent)
both functions return two values html, metadata
:
local mde = require "markdown_extra"
local html, metadata = mde.from_file("test.md")
The html
will contain your processed markdown, the metadata
will be a table with your metadata. The metadata frontmatter needs to be in YAML format. If you have an error in your frontmatter, the metadata
variable will be nil
.
Process the file specified by path
and returns both html and metadata.
Process the content specified by stringContent
and returns both html and metadata.
Change the delimiters used to find the metadata at the start of the markdown content. The default values are <!--
and -->
.
Change the options for cmark
from OPT_DEFAULT
to OPT_UNSAFE
I am using busted
for testing. You can check our test spec inside the spec
folder.