mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-07-02 01:22:07 -04:00
fix(visual_report): ignore fenced headings in TOC extraction
Strip fenced code blocks before extracting visual-report headings so heading-looking lines inside code fences do not desync TOC anchors. Add regression coverage for backtick and tilde fences while preserving normal heading extraction.
This commit is contained in:
@@ -107,6 +107,13 @@ def _extract_headings(md_text: str) -> List[Dict[str, str]]:
|
||||
headings = []
|
||||
seen_slugs: Dict[str, int] = {}
|
||||
|
||||
# Strip fenced code blocks before scanning for "## ..." lines: a heading-
|
||||
# looking comment inside ``` / ~~~ is NOT rendered as an <h2> by the
|
||||
# markdown renderer, so counting it here desynced the TOC anchor ids
|
||||
# (built by zipping these headings against the rendered <h2>/<h3>), making
|
||||
# every later TOC link point at the wrong section.
|
||||
md_text = re.sub(r'(?ms)^[ \t]*(`{3,}|~{3,})[^\n]*\n.*?^[ \t]*\1[ \t]*$', '', md_text)
|
||||
|
||||
def _plain_heading_text(text: str) -> str:
|
||||
text = text.strip().rstrip("#").strip()
|
||||
text = re.sub(r'!\[([^\]]*)\]\([^)]+\)', r'\1', text)
|
||||
|
||||
Reference in New Issue
Block a user