#content

    Page formats: how a source file becomes HTML after templating.

    Import as justjavac/fus/content.

    • ContentFormat::new(name, exts, render) describes one format. render receives the already-templated body, so a format never needs to know which engine produced it.
    • ContentRegistry maps extensions to formats: builtin, new, register, find, names, extensions, render.
    • render_body(body, ext, data, env, registry) templates the body with the page data, then applies the format registered for the extension.

    Built in: Markdown (.md, .markdown) and HTML (.html, .htm, .jinja, .j2, .liquid). Adding AsciiDoc or MDX is one register call; the build and the CLI stay untouched.

    ContentFormat

    pub struct ContentFormat {
    name : String
    exts : Array[String]
    render : (StringView) -> String
    }

    One page format.

    render receives the templated body and returns HTML. Formats that are already HTML use the identity function; Markdown converts.

    ContentFormat::new

    fn ContentFormat::new(name : String, exts : Array[String], render : (StringView) -> String) -> ContentFormat

    Create a page format.

    exts are lowercase extensions without a dot. render receives the already templated body, so a format never needs to know about the template engine.

    ContentRegistry

    pub struct ContentRegistry {
    formats : Array[ContentFormat]
    }

    A registry of page formats, keyed by extension.

    ContentRegistry::builtin

    Create a registry with Markdown and HTML registered.

    .jinja, .j2 and .liquid are HTML pages whose template dialect is picked by the engine registry, so they share the identity transform.

    ContentRegistry::extensions

    fn ContentRegistry::extensions(self : ContentRegistry) -> Array[String]

    Every extension handled by the registry, in registration order.

    ContentRegistry::find

    fn ContentRegistry::find(self : ContentRegistry, path : StringView) -> ContentFormat?

    The format handling path, if any.

    ContentRegistry::names

    fn ContentRegistry::names(self : ContentRegistry) -> Array[String]

    Names of the registered formats, for diagnostics.

    ContentRegistry::new

    Create an empty registry.

    ContentRegistry::register

    fn ContentRegistry::register(self : ContentRegistry, format : ContentFormat) -> Unit

    Register a format. Later formats win for a shared extension.

    ContentRegistry::render

    fn ContentRegistry::render(self : ContentRegistry, path : StringView, html : String) -> String

    Transform a templated body into HTML using the format for path.

    Unknown extensions are emitted as-is, so a page may use any extension as long as it is listed in pageExtensions.

    render_body

    fn render_body(body : String, src : StringView, ctx :
    Json
    , env :
    TemplateEnv
    , registry : ContentRegistry) -> String

    Render a page body: template first, then the format transform.

    Templating runs before Markdown so that a {% for %} loop can generate list items or table rows that Markdown then parses as real blocks.

    Source Files