fix: Sprungziel für Notenverweise aus HTML-Tabellen bei GFM-Fußnoten (QA2-03)
Wird dieselbe Anmerkung aus einer als HTML erhaltenen Tabelle und aus dem Fließtext referenziert, entstand nur eine [^fn-…]-Definition; der HTML-Verweis <a href="#fn-…"> lief ins Leere. Die Definition erhält in diesem Fall zusätzlich den Anker <a id="fn-…">. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
467b070326
commit
def1d8b5c0
2 changed files with 18 additions and 0 deletions
|
|
@ -936,6 +936,9 @@ class Renderer:
|
||||||
blocks = self.render_note(note) or ["(leer)"]
|
blocks = self.render_note(note) or ["(leer)"]
|
||||||
body = "\n\n".join(blocks)
|
body = "\n\n".join(blocks)
|
||||||
if note.label in self.md_ref_labels:
|
if note.label in self.md_ref_labels:
|
||||||
|
if f"{self.file}:{note.label}" in self.note_refs:
|
||||||
|
# also referenced from an HTML table (<a href="#fn-…">): give that link a target
|
||||||
|
body = f'<a id="{note.label}"></a>' + body
|
||||||
out.append(indent_block(body, f"[^{note.label}]: ", " "))
|
out.append(indent_block(body, f"[^{note.label}]: ", " "))
|
||||||
else:
|
else:
|
||||||
num = int(note.label.split("-")[1])
|
num = int(note.label.split("-")[1])
|
||||||
|
|
|
||||||
|
|
@ -59,3 +59,18 @@ def test_backlink_after_code_block_does_not_break_fence_end_of_book(convert):
|
||||||
assert _fences_closed(notes), notes
|
assert _fences_closed(notes), notes
|
||||||
assert not re.search(r"\*\*\d+[:.]\*\* ```", notes), "Fence hinter Notennummer ist kein Codeblock"
|
assert not re.search(r"\*\*\d+[:.]\*\* ```", notes), "Fence hinter Notennummer ist kein Codeblock"
|
||||||
assert "[↩](001-k.md#fnref-001)" in notes
|
assert "[↩](001-k.md#fnref-001)" in notes
|
||||||
|
|
||||||
|
|
||||||
|
NOTE_IN_HTML_TABLE = ('<h1>K</h1><table><tr><td colspan="2">Zelle<a epub:type="noteref" href="#n1" id="r1">1</a></td></tr>'
|
||||||
|
"<tr><td>a</td><td>b</td></tr></table>"
|
||||||
|
'<p>Text<a epub:type="noteref" href="#n1" id="r1b">1</a>.</p>'
|
||||||
|
'<aside epub:type="footnote" id="n1"><p>Die Note.</p></aside>')
|
||||||
|
|
||||||
|
|
||||||
|
def test_note_referenced_from_html_table_and_text_has_target(convert):
|
||||||
|
"""QA2-03: GFM: the HTML-table reference pointed to #fn-001, but only a [^fn-001] definition existed."""
|
||||||
|
run = convert(Book(docs=[Doc("c.xhtml", NOTE_IN_HTML_TABLE)]))
|
||||||
|
text = run.chapter("001")
|
||||||
|
assert 'href="#fn-001"' in text and "Text[^fn-001]." in text
|
||||||
|
assert re.search(r'id="fn-001"', text), text
|
||||||
|
assert run.report["output_link_check"]["broken_count"] == 0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue