$5 x^2 ~x", "a\\*b \\[1\\] \\
\\$5 x\\^2 \\~x"),
])
def test_md_escape_round_trip(text, escaped):
assert p.md_escape(text) == escaped
assert p.md_unescape(escaped) == text
def test_pymupdf4llm_patch_escapes_text_but_not_code():
spans = [
{"text": "__add__ und *", "flags": 0, "char_flags": 16, "font": "x", "block": 0, "line": 0},
{"text": "a_b*c", "flags": 8, "char_flags": int(p.VISIBLE_TEXT), "font": "Courier",
"block": 0, "line": 0},
]
output, _ = p.document_layout.get_styled_text(spans)
assert output.strip() == "\\_\\_add\\_\\_ und \\* `a_b*c`"
def test_escaped_text_survives_link_steps():
md = "\\_\\_add\\_\\_, 180\\\nSiehe https://a.de/Leitlinien\\_ x.\n"
out = p.link_anchors(p.link_urls(md, ["https://a.de/Leitlinien_x"]), [])
assert out.startswith("\\_\\_add\\_\\_, 180\\\n")
assert "