Bind number-only Part headings to shared navigation translations
This commit is contained in:
@@ -115,7 +115,10 @@ def _headings(soup, target, label):
|
||||
group = blocks[start:end]
|
||||
if any(len(plain(t.get_text())) > 300 for t in group): break
|
||||
combined = ' '.join(t.get_text(' ', strip=True) for t in group)
|
||||
if title_identity(combined) == identity and identity:
|
||||
number_only = (not identity and len(group) == 1 and group[0].name in HEADINGS
|
||||
and number_info(label)[0] is not None
|
||||
and number_info(combined) == number_info(label))
|
||||
if title_identity(combined) == identity and (identity or number_only):
|
||||
matches.append(group)
|
||||
# A number leaf and the subtitle alone can both match after stripping a
|
||||
# numeric prefix. Prefer the complete adjacent title group.
|
||||
@@ -225,11 +228,11 @@ def normalize_heading_html(record, html):
|
||||
and re.fullmatch(r'[章部篇][::]?',plain(str(nodes[2])))):
|
||||
nodes[1].replace_with(chinese_number(record['number']))
|
||||
nodes[2].replace_with('章' if record['role']=='chapter' else '部')
|
||||
elif re.fullmatch(r'(?:\d+|[IVXLCDM]+|第[零一二三四五六七八九十百千万\d]+[章部篇])',compact,re.I):
|
||||
elif re.fullmatch(r'(?:\d+|[IVXLCDM]+|第[零一二三四五六七八九十百千万\d]+(?:章|部分?|篇))',compact,re.I):
|
||||
node.replace_with(prefix)
|
||||
if len(nodes)>1 and plain(str(nodes[1])) in {':',':'}: nodes[1].replace_with('')
|
||||
elif re.match(r'^第[零一二三四五六七八九十百千万\d]+[章部篇]',compact):
|
||||
node.replace_with(re.sub(r'^第[零一二三四五六七八九十百千万\d]+[章部篇]',prefix,compact))
|
||||
node.replace_with(re.sub(r'^第[零一二三四五六七八九十百千万\d]+(?:章|部分?|篇)',prefix,compact))
|
||||
return root.decode_contents()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user