render_html(
input,options) ->html,err
Render markdown to semantic HTML5
Parses and renders markdown through the HTML renderer. options goes to
the renderer whole. Options:
diagrams: draw a mermaid fence as an inline SVG in a
<figure class="diagram"> (default true); a source that gives no
picture is a code block either waydiagram_cols: the page's width in cells (default 80); a diagram
wider than that is laid out compact, and drawn even when still wider,
in the direction its source givesThe page may come from a writer the site does not trust. So the renderer
checks a destination before it writes it to href or src. A destination
with no scheme passes: a relative path, a #fragment, //host/path. So
does one with a scheme from this table:
| Scheme | Use |
|---|---|
http, https | a web page |
mailto, tel | an address, a phone number |
wiki, media | a WIKIDB entry and its media, which the caller rewrites |
Any other scheme is refused: javascript:, vbscript:, data:, file:
and the rest. A refused link is its text, with no <a>. A refused image
is its alt text, with no <img>. An allowed destination goes out as
written.
The scheme is read as a browser reads it. Leading spaces and control bytes
are dropped, tabs and newlines inside it are dropped, and case is ignored.
So host:8080/path has the scheme host, and is refused: write
//host:8080/path.
An image's alt text is the plain text of its content, escaped once.
Emphasis or code inside it writes no tag, and a line break in it is a
space:  gives <img src="x.png" alt="a & b">.
An element writes its attributes in a fixed order: an image src, alt,
title, class; a video or an audio src, aria-label, title,
class; a link href, title, class; a heading id, class.
An image of a video or an audio file becomes a <video> or an <audio>
element. The extension of the destination gives the kind, in any case, with
a ?query and a #fragment cut off:
| Kind | Extensions |
|---|---|
| video | mp4, m4v, webm, ogv, mov |
| audio | mp3, wav, ogg, oga, opus, m4a, flac, aac |
The class video or audio forces the kind, for a URL with no extension:
{.video}. The first of the two words in
the class wins. Any other image stays an <img>, and a link stays a link.
The element carries controls and preload="metadata". Its src is the
destination as written, so clip.mp4#t=10,20 still cuts the clip. The alt
text is the element's name: it goes to aria-label, and to the text of a
fallback link to src inside the element. An empty alt gives no
aria-label, and the destination as the link's text. Inside a link the
fallback is the bare text, since a second <a> would nest. title and
class pass through, the class whole:
<video controls preload="metadata" src="videos/demo.mp4" aria-label="Demo run" class="small"><a href="videos/demo.mp4">Demo run</a></video>
The element stays inside its paragraph, as an image does. The page's stylesheet sizes it. The terminal renderers print such an image as any other image.