Coverage for src/lilbee/wiki/grammar.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-09-17 10:02 +0000

1"""Source of truth for the wiki's markdown grammar. 

2 

3Every structural delimiter and pattern the wiki contract depends on lives 

4here. Modules that author or parse wiki pages import from this module 

5instead of re-declaring the patterns. If the grammar ever changes, this 

6is the only file that needs to move. 

7""" 

8 

9from __future__ import annotations 

10 

11import re 

12 

13CITATION_BLOCK_SEP = "---" 

14CITATION_BLOCK_COMMENT = "<!-- citations (auto-generated from _citations table -- do not edit) -->" 

15CODE_FENCE_PREFIX = "```" 

16 

17CITE_RE = re.compile(r"\[\^(src\d+)\]") 

18FOOTNOTE_RE = re.compile(r"^\[\^(src\d+)\]:\s*(.+)$", re.MULTILINE) 

19# A prompt evidence label ([Chunk 3], [Chunks 1, 2]) echoed into prose, with 

20# the inline ">" a model glues onto it. A blockquote's own ">" is separated 

21# from the label by a space, so it stays. 

22CHUNK_MARKER_RE = re.compile(r"\s*>?\[Chunks?\s+\d+(?:\s*(?:,|and|&)\s*\d+)*\]", re.IGNORECASE) 

23INFERENCE_RE = re.compile(r"\[\*inference\*\]") 

24WIKI_LINK_RE = re.compile(r"\[\[([^\[\]]+)\]\]") 

25CODE_FENCE_RE = re.compile(r"^(```|~~~)") 

26H1_RE = re.compile(r"^#\s+(.+?)\s*#*\s*$")