fix(wiki): protect inline-code spans from cross-ref injection

_inject_cross_refs temporarily replaces backtick spans with null-byte
placeholders before injecting [[slug]] cross-refs, then restores them.
This prevents concept titles inside `code` from being rewritten.
Add tests for inline-code protection and full-list cross-ref injection.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Tarik Moussa
2026-06-14 03:49:06 +02:00
parent 0202a2266e
commit ef46d14aed
2 changed files with 54 additions and 1 deletions

View File

@@ -212,6 +212,38 @@ def test_inject_cross_refs_replaces_alias() -> None:
assert "[[circle-packing]]" in result
def test_inject_cross_refs_skips_inline_code() -> None:
"""Concept titles inside backtick inline-code spans are NOT replaced."""
concepts = [
Concept(
slug="circle-packing",
title="circle-packing",
aliases=[],
),
FIXTURE_CONCEPT,
]
# The term "circle-packing" appears both bare (should be replaced)
# and inside backticks (should NOT be replaced).
text = "Use `circle-packing` for this. See also circle-packing theory."
result = _inject_cross_refs(text, concepts, current_slug="lobachevsky-function")
assert "`circle-packing`" in result # inline-code preserved
assert "[[circle-packing]]" in result # bare occurrence replaced
def test_inject_cross_refs_full_list_even_when_single_concept() -> None:
"""Cross-ref injection uses the full concept list, not just the compiled concept."""
concepts = [
Concept(slug="circle-packing", title="Circle Packing", aliases=[]),
Concept(slug="discrete-conformal-map", title="Discrete Conformal Map", aliases=[]),
FIXTURE_CONCEPT,
]
# Compiling lobachevsky-function only; text mentions the other two concepts
text = "Discrete Conformal Map is used with Circle Packing."
result = _inject_cross_refs(text, concepts, current_slug="lobachevsky-function")
assert "[[circle-packing]]" in result
assert "[[discrete-conformal-map]]" in result
# ---------------------------------------------------------------------------
# compile_concept (full mock)
# ---------------------------------------------------------------------------