A2ML can be rendered on the web without browser changes.
-
A2ML → HTML during CI/SSG build
-
Works everywhere, no client-side cost
-
JS/Rescript parser + renderer in the browser
-
Suitable for interactive docs and embedded widgets
module Ast: {
type doc
type block
}
type parseMode = Lax | Checked
let parse: (~mode: parseMode=?, string) => result<Ast.doc, string>
let renderHtml: Ast.doc => stringSee prototype/rescript/ for a minimal Module 0 parser + HTML renderer sketch.
See docs/demo.html for a preview generated via ddraig-ssg.
See prototype/wasm/ for a direct-to-WASM sketch using rescript-wasm-runtime.
The demo page is generated from prototype/ddraig/content/demo.md using
scripts/build-demo-ddraig.sh, which compiles and runs a small Idris driver
against the ddraig-ssg repo.
just demo<script type="module">
import {parse, renderHtml} from "/a2ml.js";
const src = document.getElementById("doc").textContent;
const doc = parse(src, {mode: "Checked"});
if (doc.ok) {
document.getElementById("out").innerHTML = renderHtml(doc.value);
} else {
document.getElementById("out").textContent = doc.error;
}
</script>
<script id="doc" type="application/vnd.a2ml">
# A2ML Overview
@abstract:
A2ML is a typed, attested markup format.
@end
</script>
<div id="out"></div>For interim usage, serve A2ML with Content-Type: application/vnd.a2ml.
Use charset=utf-8 only when the document is purely textual.
class A2MLDoc extends HTMLElement {
async connectedCallback() {
const src = this.textContent;
const {parse, renderHtml} = await import("/a2ml.js");
const doc = parse(src, {mode: "Checked"});
this.innerHTML = doc.ok ? renderHtml(doc.value) : `<pre>${doc.error}</pre>`;
}
}
customElements.define("a2ml-doc", A2MLDoc);Usage:
<a2ml-doc>
# A2ML Overview
@abstract:
A2ML is a typed, attested markup format.
@end
</a2ml-doc>