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 (
importorexportat 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 (seecode_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.