Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(doc-drift): honor Markdown closing fence rules (#3239)
abhi26dbf60a88ab42
diff --git a/packages/core/src/repowise/core/analysis/doc_drift/extractor.py b/packages/core/src/repowise/core/analysis/doc_drift/extractor.pyindex 7c4ec90ff..18045a3d7 100644--- a/packages/core/src/repowise/core/analysis/doc_drift/extractor.py+++ b/packages/core/src/repowise/core/analysis/doc_drift/extractor.py@@ -88,13 +88,16 @@ def prose_lines(text: str) -> Iterator[tuple[int, str]]:m = _FENCE_RE.match(line)if m:- marker = m.group(1)[:3]+ marker = m.group(1)if not in_fence:in_fence, fence_marker = True, marker- elif marker == fence_marker:- # Only the marker that opened the fence can close it. A ``~~~``- # inside a ``` block is content, and treating it as a close- # inverts the state for the rest of the document.+ elif (+ marker[0] == fence_marker[0]+ and len(marker) >= len(fence_marker)+ and not line[m.end():].strip()+ ):+ # A closer has the same character, at least the opener's run+ # length, and no info string. Shorter or tagged runs are content.in_fence, fence_marker = False, ""continuediff --git a/tests/unit/doc_drift/test_review_regressions.py b/tests/unit/doc_drift/test_review_regressions.pyindex 6426741a1..e72aab91f 100644--- a/tests/unit/doc_drift/test_review_regressions.py+++ b/tests/unit/doc_drift/test_review_regressions.py@@ -105,6 +105,34 @@ def test_a_tilde_run_does_not_close_a_backtick_fence():assert [r.target for r in extract(text, "docs/a.md")] == ["src/real.py"]+ ("opener", "content", "closer"),+ [+ ("```", "```python", "```"),+ ("~~~", "~~~python", "~~~"),+ ("````markdown", "```", "````"),+ ("~~~~markdown", "~~~", "~~~~"),+ ("```", "``` trailing text", "```` \t"),+ ],+)+def test_only_a_long_enough_bare_fence_closes_the_block(opener, content, closer):+ text = (+ f"{opener}\n{content}\n## Example heading\n`src/invented.py`\n"+ f"{closer}\n## Real heading\nSee `src/real.py`.\n"+ )+ assert list(prose_lines(text)) == [+ (6, "## Real heading"),+ (7, "See `src/real.py`."),+ (8, ""),+ ]+ assert [(r.line, r.target) for r in extract(text, "docs/a.md")] == [+ (7, "src/real.py")+ ]+ idx = _index(docs={"docs/a.md": text})+ ref = _one("[Real](#real-heading)", DriftKind.ANCHOR)+ assert resolve(idx, ref).verdict is DriftVerdict.RESOLVED++def test_line_numbers_count_newlines_only():"""``splitlines()`` also breaks on U+2028 and friends, which arrive bycopy-paste; git does not count them, and ``line_number`` is the key."""