Converts post markdown to HTML.
Every markdown-to-HTML conversion in the blog engine goes through this
module so that a post renders identically whether it is built by
mix blog.build, served by the preview server, or summarised by the
Micropub endpoint.
Conversion uses MDEx, a CommonMark parser built on Comrak. Code blocks are then syntax highlighted with Makeup.
Enabled syntax
Beyond CommonMark, the default option set enables tables, strikethrough,
autolinks, task lists, smart punctuation, and footnotes in both the labelled
[^name] and inline ^[note] forms. Raw HTML in a post is passed through
rather than stripped, because posts are authored by the site owner rather
than submitted by untrusted visitors.
See the footnotes guide for how footnotes render and how to style them.
Configuration
The option set can be replaced or extended per-site. Options are deep-merged over the defaults, so a site only names what it wants to change:
config :static_blog, :markdown,
extension: [alerts: true],
parse: [smart: false]See MDEx.Document for the full list of accepted options.
Summary
Functions
Return the built-in markdown options, before any site configuration.
Return the markdown options in effect, with options merged over them.
Convert a markdown string to HTML.
Functions
@spec default_options() :: keyword()
Return the built-in markdown options, before any site configuration.
Returns
- A keyword list of
MDEx.Documentoptions.
Examples
iex> StaticBlog.Markdown.default_options()[:render]
[unsafe: true]
Return the markdown options in effect, with options merged over them.
Arguments
optionsis a keyword list of overrides. Defaults to[].
Returns
- A keyword list of
MDEx.Documentoptions:default_options/0, with the:markdownapplication environment merged over it, thenoptions.
Examples
iex> StaticBlog.Markdown.options()[:extension][:footnotes]
true
iex> options = StaticBlog.Markdown.options(extension: [footnotes: false])
iex> {options[:extension][:footnotes], options[:extension][:table]}
{false, true}
Convert a markdown string to HTML.
Arguments
markdownis the post body as a markdown string, without frontmatter.
Options
- Any option accepted by
MDEx.Document, such as:extension,:parse, or:render. Options given here are deep-merged over the configured defaults, which are themselves merged overdefault_options/0.
Returns
- The rendered HTML as a string.
Examples
iex> StaticBlog.Markdown.to_html("A *simple* post.")
"<p>A <em>simple</em> post.</p>"
iex> StaticBlog.Markdown.to_html("Tildes ~~strike~~ through.")
"<p>Tildes <del>strike</del> through.</p>"