Writing pages
Pages are Markdown files in your markdown folder. Merodi converts them to HTML using the CommonMark standard.
What is on by default
Standard CommonMark works with no setup: headings, paragraphs, lists, links, emphasis, code, block quotes. Raw HTML is passed through unchanged, so you can mix HTML into Markdown.
Everything else is off until a plugin turns it on. For example, without any plugin a pipe table is just text, and headings get no id. Turn things on in src/plugins/main.lua:
merodi.enable.GFM()
merodi.enable.AutoHeadingID()
merodi.enable.HTMLAttr()
Extensions
| Call | Adds |
|---|---|
merodi.enable.GFM() |
GitHub-flavored Markdown: tables, strikethrough, autolinks, task lists |
merodi.enable.Table() |
Tables only |
merodi.enable.Strikethrough() |
~~text~~ |
merodi.enable.Linkify() |
Plain URLs and emails become links |
merodi.enable.TaskList() |
- [x] task lists |
merodi.enable.DefinitionList() |
Definition lists |
merodi.enable.Footnote() |
Footnotes |
merodi.enable.Typographer() |
Curly quotes, dashes and ellipses |
merodi.enable.CJK() |
Better line handling for Chinese, Japanese and Korean |
merodi.enable.HTMLAttr() |
Attributes on Markdown blocks, see below |
GFM already contains Table, Strikethrough, Linkify and TaskList, so do not enable those next to it.
Parser options
| Call | Adds |
|---|---|
merodi.enable.AutoHeadingID() |
An id on every heading, made from its text |
merodi.enable.EscapedSpace() |
A backslash before a space keeps the space |
A heading ## Build and install gets id="build-and-install", so you can link to page.html#build-and-install.
Core parsers
These are the CommonMark parts. They are active by default, so you do not need to enable them: SetextHeading, ThematicBreak, List, ListItem, CodeBlock, ATXHeading, FencedCodeBlock, Blockquote, HTMLBlock, Paragraph, CodeSpan, Link, AutoLink, RawHTML, Emphasis. They exist as merodi.enable.<Name>() calls too.
Attributes
With merodi.enable.HTMLAttr() you can put classes, ids and other attributes on a block. Write them in braces on their own line, right after the block:
## Install
{#install .big}
A paragraph with a class.
{.lead}
- one
- two
{.compact}
> A note.
{.note}
That gives:
<h2 id="install" class="big">Install</h2>
<p class="lead">A paragraph with a class.</p>
<ul class="compact"> ... </ul>
<blockquote class="note"> ... </blockquote>
Rules:
.nameadds a class,#namesets the id, andkey=valueorkey="value"sets any other attribute. Several can share the braces:{.a .b #c title="x"}.- The braces can also end the last line of a paragraph or heading. On a heading, use the own-line form instead when you also use
AutoHeadingID, because the auto id is made from the heading text before the braces are removed. - An image sits inside a paragraph, so
{.pic}after an image line lands on the<p>, not on the<img>. [text]{.x}also puts the attributes on the surrounding block, and the brackets disappear. For a real inline<span>, write the HTML yourself.- Fenced code blocks do not render attributes.
Which attributes are kept
Merodi only writes attributes it knows. Classes, id, style, title, data-* and similar global ones are kept. Unknown ones such as foo="bar" and event handlers such as onclick are dropped. To allow everything, disable the filter in a plugin:
merodi.disable.GlobalAttribute() -- every element
merodi.disable.ParagraphAttribute() -- paragraphs
The full list is in the Lua API.
Static files
Anything that is not a .md file is copied as it is: stylesheets, images, fonts, scripts, a CNAME file. Keep them next to your pages, for example in src/md/static/, and refer to them with relative links.
Pages and fragments
A page with a {% document %} tag becomes a full HTML document. A page without one is written as a bare fragment. See Templates.
Jinja inside Markdown
Jinja runs before Markdown, so {{ ... }}, {% ... %} and {# ... #} in your text are always read by Jinja. To write them literally, wrap the text in a raw block:
{% raw %}
Use {{ name }} to print a variable.
{% endraw %}
That is how this site shows template code.