# Scriptorium Scriptorium renders scientific documents server-side in Go: Markdown into HTML, TeX mathematics into MathML Core, and Mermaid flowchart and sequence diagrams into SVG. Three engines, each written from scratch in this repository on the Go standard library alone, producing markup the reader's browser already knows how to draw: no JavaScript runs on the page that reads the result. ## The strengths, each with its proof **Complete Markdown.** The engine renders the full CommonMark 0.31.2 grammar plus the GitHub Flavored Markdown extensions. Measured against the official suites: 649 of 652 CommonMark examples pass, and the three exceptions are bare URLs and email addresses that the GFM extended autolinks turn into links, the same trade GitHub's own reference implementation makes; all 23 extension examples of the GFM specification pass byte for byte. Footnotes and definition lists come on top, rendered in the shapes GitHub and Pandoc established. **Complete mathematics.** Every one of the 391 mathematical symbols in the KaTeX coverage table maps to MathML Core, verified by a systematic diff against KaTeX's own source tables, together with fractions, radicals, scripts with movable limits, stretchy delimiters, the amsmath environments, accents, styles, colours, extensible arrows and bounded macros. Where a KaTeX-compatible renderer needs JavaScript in the reader's browser, scriptorium emits MathML Core that Chromium, Firefox and Safari draw natively. **Deterministic.** The same input produces byte-identical output on every call, in every process, on every machine. Diagram layouts break ties by the order of appearance and never by map iteration; tests assert byte equality across repeated renders in all three engines. Output is safe to cache, to diff and to sign. **Zero dependencies.** The Go standard library alone, direct and transitive. There is no `go.sum`, because there is nothing to sum: no parser to supply-chain, no renderer to version-pin, no JavaScript bundle to ship. Compiles wherever Go compiles. **Honest about its edges.** A construct outside a mappable surface is never dropped and never guessed at: mathematics degrades in place, the unknown command standing as its verbatim source inside a marked element while the rest of the expression still renders, and a diagram type outside the two grammars is refused with an error naming the type and the source line. **Ready for servers.** The engines hold no state between calls, so every function is safe for concurrent use. Rendering never fails on malformed input: Markdown and mathematics always produce output, and a diagram error tells the author the line to fix. **No sanitisation, by contract.** The library renders trusted input and writes the output verbatim; whether the result may reach a given audience is the consumer's policy. A consumer of untrusted input keeps its own sanitiser and applies it to the rendered result. ## A taste ```go package main import ( "os" "sourcedock.dev/petrbalvin/scriptorium" ) func main() { os.Stdout.Write(scriptorium.Render([]byte( "# Measured, not guessed\n\nA *claim* with [a source](/uri) and some `code`.\n"))) os.Stdout.Write(scriptorium.RenderMathDisplay([]byte(`\sum_{i=1}^{n} \frac{1}{i^2}`))) svg, err := scriptorium.RenderDiagram([]byte("flowchart LR\n A[Input] --> B{Model} --> C[Result]\n")) if err != nil { panic(err) } os.Stdout.Write(svg) } ``` The first call prints exactly: ```html
A claim with a source and some code.