Bind number-only Part headings to shared navigation translations

This commit is contained in:
Kai Tan
2026-10-08 08:38:23 +08:00
parent 644e93b874
commit 0e4aec82d8
4 changed files with 19 additions and 3 deletions
+10
View File
@@ -265,3 +265,13 @@ def test_complete_book_includes_backmatter_and_non_spine_documents(tmp_path):
assert any(e.file_path == 'Text/footnotes.xhtml' and 'Note text' in e.original_text for e in complete)
assert FineGrainedExtractor(complete_book=True)._classify_document('index.xhtml') == 'core'
assert FineGrainedExtractor(complete_book=True)._classify_document('nav.xhtml') == 'toc'
def test_number_only_part_heading_is_bound_without_matching_prose():
from src.common.html import parse_html
from src.preprocessing.navigation import _headings, normalize_heading_html
soup = parse_html('<h1 id="part">Part IV</h1><p>Unrelated epigraph.</p>')
headings, reason = _headings(soup, 'part.xhtml', 'Part IV')
assert reason is None and [h['id'] for h in headings] == ['part']
assert _headings(parse_html('<p>Part IV</p>'), 'part.xhtml', 'Part IV')[0] == []
assert normalize_heading_html({'role': 'part', 'number': 4}, '第四部分') == '第四部'