Capability first · transport second

MD.js

Renders complete Markdown with Marked and optionally maps source blocks to rendered comment anchors.

SDK 0.97.1Runtime 0.8.12Protocol arcane/1
On this page

Overview

Renders complete Markdown with Marked and optionally maps source blocks to rendered comment anchors.

  • Artifact
    MD.js · esm
  • Classification
    public first party
  • Availability
    Browser / native WebView
  • Normalization
    Complete raw and rendered Marked values; parse errors remain vendor-native. Opt-in source mapping preserves original UTF-16 offsets and adds only comment anchors to complete rendered output. Lists, quotes, and tables map at top-level block granularity; invisible source or unavailable parsed anchors use the consumer's nearest available block behavior. Mapping is rebuilt on raw replacement and append, without persistence or viewport movement.

Import and lifecycle

JavaScript
import md from '/node_modules/arcane-os/runtime/arcane/modules/MD.js';

Import applies Arcane Marked options to the shared vendored singleton. Construction, raw assignment, and append() reparse complete Markdown and rebuild opted-in source mapping; safeRendered returns the same complete rendered markup. Source mapping adds generated comment anchors only and owns no DOM scrolling or persistence.

Application-facing behavior: default MD; new MD(raw,{sourceMap:true}) enables ordered sourceMap records {start,end,marker,type}, with inclusive start/exclusive end in original UTF-16 source positions and marker equal to generated comment data. Locate anchors with a comment TreeWalker, not a CSS selector. Markers are opaque and may change after edits. sourceMap exposes the current mutable array, replaced after each successful render. raw, rendered, safeRendered, and append() remain; default sourceMap is empty and ordinary output is unchanged. Rendering and getters are DOM-independent.

Protocol and host implementation

Marked This detail does not widen the application-facing API or grant authority.

Exports, signatures, parameters, and results

BindingFormDeclaration or signatureParameter syntax
defaultdefault · classclass MD—
CallableKindExact public signatureParameter syntax
MD.appendpublic-memberappend(value='')value=''
MemberKindExact public declarationParameter syntax
MD.constructorconstructorconstructor(raw='', options={})raw='', options={}
MD.renderedgetget rendered()—
MD.safeRenderedgetget safeRendered()—
MD.sourceMapgetget sourceMap()—
MD.renderedsetset rendered(value='')value=''
MD.rawgetget raw()—
MD.rawsetset raw(value='')value=''
MD.appendmethodappend(value='')value=''

Parameter meanings and results

new MD(raw,{sourceMap:true}) opts into a sourceMap getter with ordered {start,end,marker,type} records; start is inclusive and end exclusive in UTF-16 positions of the exact original raw string. marker is complete generated comment data for TreeWalker(SHOW_COMMENT) lookup, not a CSS selector, and its prefix avoids authored-source collision. Markers are opaque and may change after edits. sourceMap exposes the current mutable array, replaced after each successful render. Rendered output remains complete with only added comment anchors, no element wrappers or attributes. Lists, quotes, and tables use top-level blocks; consumers use the nearest available block for invisible source or an anchor absorbed by raw HTML, rather than exact glyph/caret geometry. Default sourceMap is empty and uses the same parsing without anchors. Both paths use the native HTML block tokenizer first, then recognize complete standalone IMG tags with a newline in a quoted attribute as one full HTML block. These tags start at an existing block boundary with zero to three leading spaces and end on their own line or at end of source; separate inserted blocks from surrounding Markdown with blank lines. Native HTML, inline prose, fenced/indented/inline code, escaped examples, and incomplete tags retain their existing parsing. Raw source is unchanged; existing rendered line-ending normalization remains and source-map offsets address original CRLF/CR input too. raw getter/setter; rendered getter with intentionally no-op setter; safeRendered returns rendered without stripping markup; append(string) returns the updated complete raw Markdown.

Events, side effects, and errors

Source-literal CustomEvent dispatches

No source-literal CustomEvent dispatch is part of this artifact.

Lifecycle and event flow

This artifact has no additional documented lifecycle event flow.

Direct coded failures

This artifact directly assigns no stable coded failure.

Exported Error subclasses

This artifact exports no Error subclass.

Documented failure behavior

  • Marked parse exceptions can propagate.
  • Non-string raw/append input is reported through arcaneLogging.trace and leaves the existing value unchanged.

Availability and capabilities

Browser / native WebView. Complete raw and rendered Marked values; parse errors remain vendor-native. Opt-in source mapping preserves original UTF-16 offsets and adds only comment anchors to complete rendered output. Lists, quotes, and tables map at top-level block granularity; invisible source or unavailable parsed anchors use the consumer's nearest available block behavior. Mapping is rebuilt on raw replacement and append, without persistence or viewport movement.

No Core service; rendering and getters are DOM-independent. Consumers own DOM anchor lookup and viewport behavior.

Contract example

JavaScript
import MD from '/node_modules/arcane-os/runtime/arcane/modules/MD.js';

const md = new MD('# Ready\n<script>alert(1)</script>');
document.querySelector('main').innerHTML = md.safeRendered;

No direct Core call is claimed for this artifact. Any injected provider or consuming module retains its own documented authority.