Skip to main content

Module scan

Module scan 

Source
Expand description

Structural line matchers: what a line is, before anything decides what to do with it.

Each function ports one compiled pattern or one small helper from src/markdown_prose_hooks/unwrap.py, and the pattern it answers to is named in its documentation. Nothing here holds state or reads more than the line it is given.

Every expected value in the tests below was produced by running the Python rather than by reading the pattern. Reading a regex and writing down what it ought to do reproduces the reader’s misunderstanding in a second language, which is the one failure a second implementation is supposed to catch.

Functions§

has_hard_break
_has_hard_break: a trailing backslash or two trailing spaces.
is_alpha_list_line
_MATCH_ALPHA_LIST: a. / b) sub-enumerators, which CommonMark does not treat as list markers but which are still load-bearing layout.
is_closing_fence
_is_closing_fence: does body close a fence of this character and length?
is_gfm_alert
_MATCH_GFM_ALERT: [!NOTE], [!TIP]-, and the rest of the alert syntax.
is_link_reference
_MATCH_LINK_REFERENCE: [label]: with a non-empty label.
is_list_line
_MATCH_LIST: a marker at column zero followed by any Python whitespace.
is_python_space
Python’s str.isspace(), str.strip(), and \s on a str pattern.
is_raw_html_tag
_RAW_HTML_TAGS: tags whose content is literal and must not be reflowed.
is_setext_line
_MATCH_SETEXT: a run of = or a run of -, then whitespace to the end.
is_thematic_break
_MATCH_THEMATIC: three or more -, * or _, whitespace permitted between.
match_blockquote
_MATCH_BLOCKQUOTE: return (prefix, rest) for one blockquote level.
match_blockquote_prefix
_MATCH_BLOCKQUOTE_PREFIX: the byte length of the whole marker stack.
match_html_tag_name
_MATCH_HTML_TAG_NAME: the tag name of an opening tag, case preserved.
match_list_marker
_MATCH_LIST_MARKER: return (prefix, content_col, rest).
match_opening_fence
_MATCH_FENCE: return (fence_char, fence_len) for a fenced code opener.
match_opening_html_block
match_opening_html_block: the tag name of a block that stays open.
match_opening_html_literal_terminator
_match_opening_html_literal_terminator: what would close a raw HTML literal.
py_splitlines_keepends
_split_lines(keepends=True): split on \r\n, \n and \r, and nothing else.
py_trim
Python’s str.strip().
py_trim_end
Python’s str.rstrip().
py_trim_start
Python’s str.lstrip().
split_eol
_split_eol: return (body, eol) where eol is \r\n, \n, \r or empty.
starts_front_matter
_starts_front_matter: --- on line one with a reachable closer below it.
strip_blockquote_prefix
_SUB_BLOCKQUOTE_PREFIX('', body): peel every blockquote level, or none.