This commit is contained in:
douboer
2025-08-12 21:39:58 +08:00
parent fabd0225d6
commit 8873c70a60
11 changed files with 81 additions and 12 deletions

View File

@@ -109,10 +109,14 @@ def find_label_path(
if "label" in v:
new_path = path + [v["label"]]
if v["ref"] == ref and (filepos is None or v["filepos"] == filepos):
return " / ".join(new_path)
found = find_label_path(v["children"], ref, filepos, new_path)
if found:
return found
title = " / ".join(new_path)
#print(f'title ref={ref} filepos={filepos} -> {title}') #DBG
return title
title = find_label_path(v["children"], ref, filepos, new_path)
if title:
#print(f'title1 ref={ref} filepos={filepos} -> {title}') #DBG
return title
# 2. 如果带filepos查找失败回退到同ref下第一个章节即只要ref匹配就返回
if filepos is not None:
for v in nodes:
@@ -120,10 +124,13 @@ def find_label_path(
new_path = path + [v["label"]]
# print(f"对比 {v['ref']} == {ref}")
if v["ref"].split("#", 1)[0] == ref.split("#", 1)[0]:
return " / ".join(new_path)
found = find_label_path(v["children"], ref, None, new_path)
if found:
return found
title = " / ".join(new_path)
#print(f'title3 ref={ref} filepos={filepos} -> {title}') #DBG
return title
title = find_label_path(v["children"], ref, None, new_path)
if title:
#print(f'title4 ref={ref} filepos={filepos} -> {title}') #DBG
return title
# 3. 若完全未找到尝试直接解析idref所指html文件标题获取章节label信息
# 仅在顶层调用时执行此逻辑