MdxEscaper

object MdxEscaper

MDX "escaping-hell" is really FOUR channels with different rules. Routing each correctly is what retires the problem instead of hoping it away.

Types

Link copied to clipboard

Channel 3 — the raw-HTML fallback branch, the real sharp edge. Raw HTML in MDX is JSX: void tags must self-close, attributes must be quoted, and bare <, &, { in text break compilation. This renders a subtree as JSX-VALID markup so the fallback can never crash the build.

Functions

Link copied to clipboard
fun attr(value: String): String

Channel 4 — component attribute values (rendered inside double quotes).

Link copied to clipboard
fun fence(code: String): String

Channel 2 — inline code / fenced code. Content is NOT parsed as MDX, so it is emitted verbatim between delimiters. Nothing to escape; we only pick a fence long enough to contain any backtick runs already in the source.

Link copied to clipboard
fun prose(text: String): String

Channel 1 — prose text nodes. Neutralise the MDX-active characters.