feat(transit): 添加正文引用标记到书签超链接功能

- 新增 CITE_PATTERN 正则表达式匹配 [N] 引用格式
- 添加 base_dir 参数支持相对图片路径解析
- 实现书签创建和超链接替换功能
- 添加 link_body_citations 函数处理正文引用链接
- 在参考文献段落中添加书签标识
- 支持将 [N] 引用替换为指向参考文献的超链接
This commit is contained in:
zzy
2026-05-10 15:07:20 +08:00
parent 0b10e97e0c
commit 4e39a4f2ac
4 changed files with 153 additions and 7 deletions

View File

@@ -11,7 +11,7 @@ from docx import Document
from .config import load_config, ThesisConfig
from .parser import parse_markdown
from .body import body_to_paragraphs, replace_placeholder
from .body import body_to_paragraphs, replace_placeholder, link_body_citations
from .references import references_to_paragraphs
@@ -88,7 +88,12 @@ def generate_thesis(
# 5. 解析正文为段落列表
body_md = ctx.get("body_md", "")
body_paragraphs = (
body_to_paragraphs(body_md, level_offset=config.level_offset, body_style=config.body_style)
body_to_paragraphs(
body_md,
level_offset=config.level_offset,
body_style=config.body_style,
base_dir=data_path.parent,
)
if body_md else []
)
@@ -114,6 +119,10 @@ def generate_thesis(
final_doc, "__CONTEXT_PLACEHOLDER__", body_paragraphs,
default_body_style=config.body_style,
)
# 将正文中的 [N] 引用替换为超链接
link_body_citations(final_doc)
replace_placeholder(
final_doc, "__REFERENCE_PLACEHOLDER__", ref_paragraphs,
default_body_style=config.reference_style,