'update'
This commit is contained in:
23
toc_parse.py
23
toc_parse.py
@@ -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信息
|
||||
# 仅在顶层调用时执行此逻辑
|
||||
|
||||
Reference in New Issue
Block a user