Reference · Markup
markdown_page
markdown_page(str, map | null=) -> htmlWhat it does
Markdown text as a whole HTML page, for a route to answer with: what markdown makes,
inside a doctype, an <html>, and a <head> with <meta charset="utf-8">, a viewport
and a <title>. A fragment from markdown has none of these, so a browser shows it in
quirks mode. The title is the title option, or else the text of the first level-one
heading (# Title, or a line underlined with =), as it shows, without its marks, or
else empty. The options are title, lang (a language tag, written on <html>) and
html, which keeps HTML written in the text, as markdown's does.
Examples
route GET /notes = markdown_page(read_file("notes.md")?)route GET /about = markdown_page(read_file("about.md")?, { title: "About us", lang: "en" })print(markdown_page("# Notes\n\nSome *text*."))print(markdown_page("no heading", { title: "Notes", lang: "en" }))<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Notes</title></head><body><h1>Notes</h1><p>Some <em>text</em>.</p></body></html><!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Notes</title></head><body><p>no heading</p></body></html>Edge cases
- HTML in the text is shown as text unless
html: true, as withmarkdown; the title is escaped either way. - The page links no style sheet. For one, put
markdown(...)inside a view of your own with its<head>. - The result is an
htmlvalue: a route answers it astext/html. - Only a level-one heading gives the title: a
##heading is passed over, and a#line in a code block or in HTML is no heading.# Real *one*givesReal one. - It takes time in proportion to the text, as
markdowndoes, and ends at--max-compute(quillo run main.qwe --max-compute 2s) as a loop does: the request is a 500.
let title = (s) => re.find(str(markdown_page(s)), "<title>(.*)</title>").groups[0]print(title("Notes\n=====\n\ntext"), "|", title("```\n# not this\n```\n\n# Real *one*"), "|", title("## Second\n\n# First"))print(markdown_page("<b>x</b>"))print(markdown_page("<b>x</b>", { html: true, title: "<b>" }))print(type_of(markdown_page("")))Notes | Real one | First<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title></title></head><body><p><b>x</b></p></body></html><!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title><b></title></head><body><p><b>x</b></p></body></html>htmlErrors
An option it does not take, a title that is not a str, a lang that is not a
language tag, or options that are not a map, are runtime errors, not error values.
print(markdown_page("x", { titel: "a" }))line 1: `markdown_page` has no option `titel`: it takes `title`, `lang` and `html`print(markdown_page("x", { lang: "en us" }))line 1: `markdown_page`'s lang is a language tag such as "en", got "en us"Chaining
The text comes first, so a file read in a pipeline goes straight in:
write_file("notes.md", "# Today\n\n- milk")?print(read_file("notes.md")? | markdown_page({ lang: "en" }) | str | len)214See also
markdown, files, read_file, highlight
Thread 0 posts
On markdown_page(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo