Skip to main content

Module markdown

Module markdown 

Source
Expand description

Shared Markdown code-region and MDX ESM handling.

README and NatSpec escaping retain their own policies for malformed fences and prose.

FunctionsΒ§

code_regions πŸ”’
Byte ranges that Markdown parses as code under options. An HTML entity would render literally inside these ranges, so neutralization skips them. If malformed MDX cannot be parsed, returning no ranges favors neutralizing possible ESM over preserving an invalid code example byte-for-byte.
collect_code_regions πŸ”’
Collect fenced and inline code positions from the MDX-aware syntax tree.
logical_lines πŸ”’
Logical lines and their byte offsets in the original text. CRLF is one separator; lone CR and LF are separators too. The separator bytes are excluded from the returned slices and preserved in the source string.
neutralize_esm πŸ”’
Neutralize any line MDX would parse as an ESM statement (import or export at column one): the keyword’s prefix becomes HTML entities, so the line renders the same but no longer begins with an ESM token. NatSpec text can be inherited from a dependency via @inheritdoc, so this must run wherever displayed prose is assembled. A keyword that falls inside a Markdown code span or fenced code block is left untouched (see code_regions): the entity would render literally and corrupt the example, and MDX would not execute it there.
region_contains πŸ”’
Check a position against sorted, merged ranges while advancing monotonically.