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: doesbodyclose 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\son astrpattern. - 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,\nand\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)whereeolis\r\n,\n,\ror 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.