Longform Markup Language
Show HN: I built an extendable full document markup language
Last verified:
Visit Longform Markup Language
What is Longform Markup Language?
Longform Markup Language is an extendable, human-readable markup and templating language designed to produce HTML and XML fragments or complete documents. It targets scenarios where authors need precise control of semantic HTML (head, dialog, aside, templates, etc.) that Markdown either cannot express without extensions or where embedding raw HTML becomes cumbersome. The language emphasizes small, fast parsers and client-side re-use of server-rendered fragments: documents may be parsed into named fragments which a client application can select from the pristine DOM, rehydrate, and reuse for client-side navigation or state changes. Longform Markup Language includes a directive system (for example @template, @patchable, @allow-elements) to control sanitization, editing/patching behavior, templating inputs, and document-wide settings, making it suitable for CMSs, static site generators, client-server applications that rely on fragment exchange, and editors that need fine-grained control over what user-supplied markup is allowed. The spec documents fragment types (root, embedded, bare, range, text), element and attribute declaration syntax, chaining and preformatted blocks, templating variable expansion, and security considerations for sanitizers and PATCH-based editing; it is intended for developers building parsers, client runtimes, editors, or frameworks that want a transportable, semantically rich document format.
Longform Markup Language pricing
Pricing model: Freemium
The website is a specification and documentation for the Longform language and parser; there is no pricing information on the site and no paid plans documented. Implementation artifacts (parser source and example tooling) are presented as open specification content and examples, and the spec describes a small, embeddable parser rather than a commercial product or subscription offering.
Longform Markup Language pros
- Expresses full HTML and XML semantics without falling back to raw HTML
- Designed to output named fragments for client-side rehydration
- Supports root fragments that emit complete documents
- Small parser footprint (example: ~4.1 kB minified+gzipped)
- Fast line-by-line parsing approach (no AST required)
- Directive system for granular control (@allow-elements, @allow-attributes)
- Templating with string key-value inputs and safe expansion rules
- Fragment embedding and fragment identifiers for modular documents
- Explicit sanitization directives designed to integrate with Web APIs
- PATCH support for editing documented fragments via text/vnd.longform
- Editable fragments with @editable and per-fragment sanitization rules
- Range, bare, and text fragment types cover varied use-cases
- Extensible via custom directives and media type extensions
- Clear rules for element ids, classes, attributes, and chaining syntax
- Designed to interoperate with client-side DOM selection and state management
Longform Markup Language cons
- Requires an external sanitizer implementation for safe HTML handling
- Templating only accepts string key-value inputs (no built-in loops/ifs)
- Complex nested structures can become densely indented and harder to read
- Fragments that cannot embed attributes (text fragments) cannot be sourced from DOM
- Parser must embed meta information for DOM selection which increases integration complexity
- Client runtimes must implement selection and rehydration protocols (not provided)
- PATCH semantics place server-side responsibility for sanitization and merging
- Non-standard directives must be ignored by base parsers, requiring coordination for extensions
Frequently asked questions about Longform Markup Language
What is Longform used for?
Longform is used to author documents that output HTML or XML fragments (or complete documents) with precise semantic structure; it is particularly useful when multiple server-rendered fragments must be merged, selected, and re-used by a client application or when templates and editable fragments are required for client-side rendering and patching.
How does Longform differ from Markdown?
Unlike Markdown, Longform is designed to express any HTML element and attributes natively without embedding raw HTML or extensions; it focuses on fragment semantics, directives for sanitization and patching, and explicit fragment identifiers for client-side rehydration rather than lightweight prose formatting alone.
Can Longform output a full HTML document?
Yes — a Root Fragment (optionally prefixed with @doctype or @xml directives) allows a Longform file to render a complete HTML or XML document rather than just fragments.
How are fragments identified and referenced?
Fragments use embedded identifiers (single-hash, double-hash for bare fragments, and range fragments) declared on their own lines; these identifiers become selectable metadata in the parser output so clients can reference or embed fragments using a URI fragment or the #[fragment-id] embedding syntax.
How does templating work in Longform?
Templates are declared with @template and accept string key-value inputs; variables are expanded using single-hash or double-hash forms (double-hash allows insertion of Longform/HTML strings but requires sanitization rules to be configured), and complex control flow (loops/conditionals) is intentionally left to the client runtime.
What sanitization options exist?
Longform provides directives like @allow-elements, @allow-attributes, @allow-data-attributes, and @allow-all to define allowed markup; parser implementations must integrate a sanitizer (e.g., Sanitizer API, DOMPurify) to enforce these rules for embedded HTML or non-escaped template expansions.
Can I patch documents over HTTP?
Yes — Longform defines PATCH semantics using the text/vnd.longform media type; documents must set @id and @patchable and mark editable fragments with @editable, after which servers are expected to locate, sanitize, and merge edits from PATCH requests.
What security considerations should implementors follow?
Implementors must ensure sanitization of untrusted content, avoid id/data-attribute collisions (prefer generated unique selectors), expose selector strings for client reconstruction, and be cautious when re-attaching fragments to DOM to prevent manipulation by third-party scripts or extensions.
Is Longform extensible?
Yes — Longform supports custom directives and media-type extensions (e.g., text/vnd.x-example+longform) so host systems can add DSLs or editor-specific features while remaining compatible with base parsers that ignore unknown directives.
What parser/runtime support exists?
The spec describes a small, fast parser and shows example usage; the site references a lightweight parser implementation (not a commercial runtime) and expects implementors to build client runtimes that select fragments from the pristine DOM and handle sanitization, patch behavior, and template rendering.