wdpr
    Preparing search index...

    Manages rendering state and accumulates HTML output for a single render pass.

    The context is created once per call to renderToHtml and threaded through every element renderer. It provides:

    • An HTML output buffer (push, pushEscaped, getOutput)
    • Sequential counters for footnotes, TOC entries, equations, etc.
    • ID generation that optionally appends a random suffix to avoid collisions when multiple rendered fragments coexist on the same page
    • Resolution of ImageSource and LinkLocation values into concrete URLs, applying Wikidot page-name normalization rules
    • Attribute rendering with XSS sanitization
    • A bibliography map built by scanning the AST for bibliography-block elements, assigning continuous 1-indexed citation numbers across blocks
    Index

    Constructors

    • Create a new render context from a parsed syntax tree.

      Parameters

      • tree: SyntaxTree

        The syntax tree produced by the parser. Footnotes, styles, html-blocks, and table-of-contents data are extracted from the tree and stored for later use by element renderers.

      • options: RenderOptions = {}

        Caller-supplied render configuration. Missing fields fall back to safe defaults.

      Returns RenderContext

    Properties

    bibliographyEntries: DefinitionListItem[]

    Ordered bibliography definition-list entries from [[bibliography]] blocks.

    bibliographyMap: Map<string, number>

    Map from bibliography label to its 1-indexed citation number.

    footnotes: Element[][]

    Footnote element arrays collected from the syntax tree.

    htmlBlocks: string[]

    Raw HTML strings for [[html]] blocks, indexed by insertion order.

    options: RenderOptions

    Full render options supplied by the caller.

    Merged wikitext settings (page-mode defaults when omitted).

    styles: string[]

    CSS <style> blocks extracted from the syntax tree.

    tocElements: Element[]

    Pre-built TOC element tree for [[toc]] rendering.

    Accessors

    Methods

    • Generate a fixed element ID (no index). When useTrueIds is false, appends a random suffix.

      Parameters

      • name: string

      Returns string

    • Generate an element ID. When useTrueIds is true, returns ${prefix}${index}. When false, appends a random suffix to prevent collisions across fragments.

      Parameters

      • prefix: string
      • index: string | number

      Returns string

    • Join all buffered HTML fragments and return the final HTML string.

      Returns string

      The complete rendered HTML output.

    • Advance the bibliography citation counter and return the new value. Used to generate unique bibcite-N-XXXXX element IDs.

      Returns number

      The counter value after incrementing (1-based).

    • Return the current equation index and advance the counter.

      Returns number

      The index before incrementing (0-based).

    • Return the current footnote index and advance the counter.

      Returns number

      The index before incrementing (0-based).

    • Return the current HTML block index and advance the counter.

      Returns number

      The index before incrementing (0-based).

    • Return the current TOC heading index and advance the counter.

      Returns number

      The index before incrementing (0-based).

    • Append a raw HTML string to the output buffer without escaping.

      Parameters

      • html: string

        Trusted HTML fragment to append.

      Returns void

    • HTML-escape the given text and append it to the output buffer.

      Parameters

      • text: string

        Untrusted text content (will be entity-escaped).

      Returns void

    • Sanitize and render an attribute map to an HTML attribute string.

      Dangerous attributes (event handlers, unsafe URLs) are stripped by sanitizeAttributes. Each surviving key-value pair is escaped and formatted as key="value".

      Parameters

      • attributes: Record<string, string>

        Raw attribute map from the AST.

      Returns string

      A string of HTML attributes with a leading space, or "" if empty.

    • Resolve an ImageSource to a concrete src URL string.

      Wikidot supports several image source forms:

      • url -- a direct URL or local path
      • file1 -- a file attached to the current page (/local--files/{page}/{file})
      • file2 -- a file attached to a named page
      • file3 -- a file on a named site and page

      Local paths (starting with / but not //) and file-type sources are blocked when allowLocalPaths is false in the settings.

      Parameters

      • source: ImageSource

        The image source descriptor from the AST.

      Returns string | null

      The resolved URL, or null if the source is blocked by settings.

    • Resolve a LinkLocation to an href string.

      Handles plain URL strings and structured PageRef objects. For page references the page name is normalized to lowercase, spaces are replaced with hyphens, and slashes become hyphens (Wikidot URL convention). Anchors (#) and cross-site references (site field) are handled.

      Parameters

      • location: LinkLocation

        A raw URL string or a PageRef object from the AST.

      Returns string

      The resolved href string, always starting with / for local pages or https:// for cross-site links.