Expand description
Masks the code in a piece of Markdown, so text scanners can skip it (#2003).
A quoted error message or example inside a fenced code block or an inline
code span is not prose: owner/repo#123 in one is an example, not a
reference. mask_code replaces every code character with
MASK_CHAR, leaving everything else (including every newline) as it
was, so an existing regex can run on the result unchanged.
This is deliberately a small subset of CommonMark, not a parser:
- Fenced blocks are recognised only when closed. CommonMark runs an
unclosed fence to the end of the document, but an unclosed fence would
then hide every citation after it. Leaving it as text falls back to the
pre-#2003 behaviour, which is the safe direction. A fence may be indented
(a list item’s) or quoted (
>), which is why indentation is not limited: an indented code block is not recognised either way, and a fence-looking line inside one only matters if a matching closer follows. - Inline spans must open and close within one paragraph, so a stray backtick cannot pair with one paragraphs later and mask what lies between. A fenced block ends the paragraph it interrupts, and a backslash-escaped backtick cannot open a span.
- Indented code blocks are not recognised: without a full parser they cannot be told apart from list continuation.
Callers with several bodies (an issue and its comments) must mask each one on its own, so an unclosed fence or a stray backtick in one cannot pair with markup in another.
Functions§
- mask_
code - Returns
textwith fenced code blocks and inline code spans replaced byMASK_CHAR, newlines preserved.