markdown.render_html

markdown

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:

The 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:

SchemeUse
http, httpsa web page
mailto, telan address, a phone number
wiki, mediaa 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: ![**a** & b](x.png) gives <img src="x.png" alt="a &amp; 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:

KindExtensions
videomp4, m4v, webm, ogv, mov
audiomp3, wav, ogg, oga, opus, m4a, flac, aac

The class video or audio forces the kind, for a URL with no extension: ![x](https://example.com/watch){.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.