markdown

API

Every public top-level function in io.github.edadma.markdown — parsing, rendering, helpers.

All public functions live in the package object — import io.github.edadma.markdown.* and you have everything below.

Parsing

FunctionReturnsNotes
parseDocumentContent(input, config?)DocumentMost common entry point. Throws away the link reference table.
parseDocumentContentWithRefs(input, config?)(Document, Map[String, LinkReference])Use when you need the link references for cross-document analysis.
parseDocument(stream, config?)(Document, Map[String, LinkReference])Lower level — takes a LazyList[C] from InputReader.
def parseDocumentContent(
    input:  String,
    config: MarkdownConfig = MarkdownConfig.default,
): Document

def parseDocumentContentWithRefs(
    input:  String,
    config: MarkdownConfig = MarkdownConfig.default,
): (Document, Map[String, LinkReference])

def parseDocument(
    stream: LazyList[C],
    config: MarkdownConfig = MarkdownConfig.default,
): (Document, Map[String, LinkReference])

HTML rendering

FunctionReturnsNotes
renderToHTML(md: String, config?)StringParse + render. The one-line case.
renderToHTML(node: Node, config?)StringRender an existing AST. Errors if node is an inline.
renderBlockToHTML(node: Block, config?)StringRender a single block — without the trailing newline renderToHTML adds.
renderInlines(inlines: List[Inline])StringRender inline content with no surrounding <p>.
plainText(inlines, escape: Boolean = false)StringStrip all formatting. escape=true runs the result through escapeXml.
def renderToHTML(md:   String, config: MarkdownConfig = MarkdownConfig.default): String
def renderToHTML(node: Node):                                                      String
def renderToHTML(node: Node,   config: MarkdownConfig):                            String

def renderBlockToHTML(node: Block, config: MarkdownConfig = MarkdownConfig.default): String

def renderInlines(inlines: List[Inline]):                              String
def plainText   (inlines: List[Inline], escape: Boolean = false):      String

XML rendering

FunctionReturnsNotes
renderToXML(doc: Document, system?)StringEmits CommonMark XML format with <?xml … ?> declaration and DTD. Headings rendered as plain text.
escapeXml(s: String)StringEncodes &, <, >, ". Used internally; exposed for renderer authors.
def renderToXML(doc: Document, system: String = "document"): String
def escapeXml  (s: String):                                  String

URL helpers

FunctionReturnsNotes
percentEncode(input: String)StringURI percent-encoding. Treats % as already-safe to avoid double-encoding pre-encoded URLs.

AST walking helpers

FunctionReturnsNotes
Document.headingsList[Heading]All top-level Heading blocks, in source order.
extractHeaders(doc: Document)List[(Int, String)](level, plain-text-content) pairs.
inlinesToPlainText(inlines: List[Inline])StringLighter alternative to plainText — drops only Text, CodeSpan, Emphasis, Strong, and bare C cursors.
plainText(inlines, escape?)StringRecommended. Handles every inline type and strips images, links, math, etc., to their text content.
def extractHeaders(document: Document):       List[(Int, String)]
def inlinesToPlainText(inlines: List[Inline]): String

Input layer

You’ll rarely call these directly — parseDocumentContent wraps them — but they’re public for renderer / formatter authors:

FunctionReturnsNotes
new InputReader(input).streamLazyList[C]The cursor stream. Normalizes line endings and resolves backslash escapes.
rawText(cursors: List[C])StringReconstruct source text, restoring backslashes for literal-flagged characters. Used by code-block parsers.
expandLeadingTabs(line, startCol = 0)List[C]Expand tabs to spaces in leading whitespace only.
virtualIndent(line: List[C])IntTab-aware indent count of a line.
dropIndent(line, n, startCol = 0)List[C]Remove n columns of (tab-aware) leading indent.

Config

MarkdownConfig is one big case class with one copy constructor. Two prefab values:

ValueMeaning
MarkdownConfig.defaultPure CommonMark — no extensions enabled.
MarkdownConfig.allEvery extension enabled.

See Options for the per-flag table.

Doc-tag extension

case class TagDefinition(
  name:          String,
  acceptsTarget: Boolean,
  contentMode:   ContentMode,
)

final class TagRegistry:
  def lookup(name: String): Option[TagDefinition]
  def isEmpty:  Boolean
  def nonEmpty: Boolean
  def all:      Iterable[TagDefinition]

object TagRegistry:
  val empty: TagRegistry
  def apply(defs: TagDefinition*):           TagRegistry
  def fromList(defs: Iterable[TagDefinition]): TagRegistry

enum ContentMode:
  case Opaque, InlineMarkdown, BlockMarkdown

case class DocTagConfig(
  enabled:           Boolean      = false,
  registry:          TagRegistry  = TagRegistry.empty,
  strictUnknownTags: Boolean      = false,
)

object DocTagConfig:
  val disabled: DocTagConfig

See Extensions → Doc-tags for the integration model.