fix: Zeilen aus nur - oder = als Text maskieren (QA2-08)
Ein Absatz "---" wurde zur Trennlinie, "===" bzw. "---" nach einem Zeilenumbruch machte die vorige Zeile zur Setext-Überschrift. Solche Zeilen erhalten jetzt einen Backslash. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ff1a0ae5e4
commit
daa99415b5
2 changed files with 12 additions and 0 deletions
|
|
@ -116,6 +116,9 @@ def escape_line_starts(text: str) -> str:
|
|||
token = m.group(2)
|
||||
pos = m.start(2) + (len(token) - 1 if token[0].isdigit() else 0)
|
||||
line = line[:pos] + "\\" + line[pos:]
|
||||
elif re.fullmatch(r"\s*(-+|=+)\s*", line): # thematic break / setext underline
|
||||
pos = len(line) - len(line.lstrip())
|
||||
line = line[:pos] + "\\" + line[pos:]
|
||||
out.append(line)
|
||||
return "\n".join(out)
|
||||
|
||||
|
|
|
|||
|
|
@ -109,6 +109,15 @@ def test_multiple_blank_lines_inside_code_are_kept(convert):
|
|||
assert "\n\n\n" not in text.replace(code, "") # outside code blank lines are still normalized
|
||||
|
||||
|
||||
def test_dash_and_equals_lines_stay_text(convert):
|
||||
"""QA2-08: a paragraph '---' became a thematic break, '===' after a line break a setext heading."""
|
||||
body = "<h1>K</h1><p>---</p><p>Zeile<br/>===</p><p>Text<br/>-----</p>"
|
||||
text = convert(Book(docs=[Doc("c.xhtml", body)])).chapter("001")
|
||||
assert "\n\\---\n" in text, text
|
||||
assert "Zeile\\\n\\===" in text, text
|
||||
assert "Text\\\n\\-----" in text, text
|
||||
|
||||
|
||||
def _simple() -> Book:
|
||||
return Book(docs=[Doc("c.xhtml", "<h1>K</h1><p>Text.</p>")])
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue