Chemenu kompiliert Rohnotizen zu einem verlinkten, quellengebundenen Wiki: raw/ -> types/ + tools/ -> kb/ -> reports/. Was mechanisch ist, macht tools/wikitool; was Urteil braucht, macht ein Agent unter Contracts, deren Grenzen in Code durchgesetzt sind statt im Prompt. Dieser Commit ist der Startpunkt der oeffentlichen Historie. Die vorherige Entwicklung fand in einer privaten Instanz statt und ist nicht Teil dieses Repositorys; ihre Erzaehlung steht vollstaendig in CHANGES.md, das mit 44 Eintraegen von 0.1.0 bis 2.1.0 erhalten geblieben ist. Der mitgelieferte Korpus ist ein Testbett und eine Demo: 170 Seiten ueber den Stack selbst - Gates, Lint, Versionierung, Suche, das Wiki-Muster. Er dokumentiert das Werkzeug mit den eigenen Mitteln des Werkzeugs. Lizenz: AGPL-3.0 fuer den Stack (tools/, types/), CC-BY-4.0 fuer die Inhalte. Die Grenze zwischen beiden ist der Dateiplan, den dist export berechnet - siehe NOTICE.
90 lines
3.3 KiB
Python
90 lines
3.3 KiB
Python
"""strip_code_spans() - the single place that separates wiki notation from a
|
|
page that merely shows it. Every check downstream (wikilinks, citation
|
|
references and definitions, the quote limit) trusts these properties, so they
|
|
are asserted here rather than re-derived per check."""
|
|
|
|
from chemenu.markdown_code import strip_code_spans
|
|
|
|
|
|
def test_offsets_and_line_structure_survive():
|
|
"""split_cite_block() matches against the masked body and slices the real
|
|
one, so masking may never change a single offset."""
|
|
body = "a `code` b\n\n```py\nfenced\n```\n\ntail\n"
|
|
masked = strip_code_spans(body)
|
|
assert len(masked) == len(body)
|
|
assert masked.count("\n") == body.count("\n")
|
|
assert masked.index("tail") == body.index("tail")
|
|
|
|
|
|
def test_fenced_block_is_masked_including_its_fences():
|
|
body = "before\n\n```\n[^s-example]: [[Source - X]]\n```\n\nafter\n"
|
|
masked = strip_code_spans(body)
|
|
assert "[^s-example]" not in masked
|
|
assert "```" not in masked
|
|
assert "before" in masked and "after" in masked
|
|
|
|
|
|
def test_tilde_fence_and_info_string():
|
|
body = "~~~yaml\nkey: [[Value]]\n~~~\nprose [[Real]]\n"
|
|
masked = strip_code_spans(body)
|
|
assert "[[Value]]" not in masked
|
|
assert "[[Real]]" in masked
|
|
|
|
|
|
def test_longer_fence_is_not_closed_by_a_shorter_run():
|
|
"""CommonMark: the closer must be at least as long as the opener. A short
|
|
run inside is content, not the end of the block."""
|
|
body = "````\n```\n[[Inside]]\n````\n[[Outside]]\n"
|
|
masked = strip_code_spans(body)
|
|
assert "[[Inside]]" not in masked
|
|
assert "[[Outside]]" in masked
|
|
|
|
|
|
def test_unclosed_fence_runs_to_the_end():
|
|
body = "prose [[Kept]]\n\n```\n[[Swallowed]]\n\nstill code\n"
|
|
masked = strip_code_spans(body)
|
|
assert "[[Kept]]" in masked
|
|
assert "[[Swallowed]]" not in masked
|
|
|
|
|
|
def test_inline_span_is_masked_but_its_line_survives():
|
|
body = "Write it as `[^cite-id]` in prose.\n"
|
|
masked = strip_code_spans(body)
|
|
assert "[^cite-id]" not in masked
|
|
assert masked.startswith("Write it as ")
|
|
assert masked.rstrip().endswith("in prose.")
|
|
|
|
|
|
def test_multi_backtick_span():
|
|
body = "Nested: ``a `b` [[C]]`` done.\n"
|
|
assert "[[C]]" not in strip_code_spans(body)
|
|
|
|
|
|
def test_real_notation_next_to_a_mentioned_one_survives():
|
|
"""The masking must not swallow more than the span - a finding that
|
|
disappears is invisible in a way a false positive never is."""
|
|
body = "The marker `[^s-mentioned]` documents [^s-real] which is a citation.\n"
|
|
masked = strip_code_spans(body)
|
|
assert "[^s-mentioned]" not in masked
|
|
assert "[^s-real]" in masked
|
|
|
|
|
|
def test_unclosed_backtick_masks_nothing():
|
|
"""A missing closing backtick is a common typo. Matching across the
|
|
newline would turn it into a silently masked paragraph."""
|
|
body = "An open `backtick here\nand [[Still A Link]] below.\n"
|
|
masked = strip_code_spans(body)
|
|
assert "[[Still A Link]]" in masked
|
|
|
|
|
|
def test_indented_lines_are_not_treated_as_code():
|
|
"""Four spaces is a nested list continuation far more often than it is
|
|
code in this corpus - see the module docstring."""
|
|
body = "- item\n - [[Nested Link]] auslösen\n"
|
|
assert "[[Nested Link]]" in strip_code_spans(body)
|
|
|
|
|
|
def test_body_without_code_is_returned_unchanged():
|
|
body = "# Title\n\nProse with [[A Link]] and a [^s-cite].\n"
|
|
assert strip_code_spans(body) == body
|