This commit is contained in:
跨越晨昏 2024-09-07 19:24:07 +08:00
parent 946ec5464b
commit b35d61dec7

View File

@ -301,12 +301,12 @@ class Syllabus:
""" """
def __init__(self, text): def __init__(self, text):
self.text = text self.text = text
self.syllabus = [num for num, txt in re.findall(r'([\.|\d]+) ([^ ]+?)\n', self.text) if not num.endswith('.')] # 找出提纲 self.syllabus = {tuple(num.split('.')): txt for num, txt in re.findall(r'([\.|\d]+) ([^ ]+?)\n', self.text) if not num.endswith('.')} # 找出提纲
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs):
for num in self.syllabus: for num, txt in self.syllabus.items():
# 检测层级 self.text = re.sub(f'{".".join(num)} {txt}', f'<h{len(num)}>{".".join(num)} {txt}#{{' + '.'.join(num) + f'}}</h{len(num)}>', self.text) # 按照层级为提纲添加不同等级的标题并创建锚点
self.text = re.sub(f'({num}) .+?', '', self.text) return self.text
class Basic: class Basic:
@ -320,7 +320,7 @@ class Basic:
:param text: 原始文本 :param text: 原始文本
:return: 移除强注释后的文本 :return: 移除强注释后的文本
""" """
return re.sub('\|=[\s\S]=|', '', text) return re.sub('\|=[\s\S]*=\|', '', text, re.DOTALL)
@staticmethod @staticmethod
def week_annotation(text: str) -> str: def week_annotation(text: str) -> str:
@ -377,9 +377,9 @@ def body(text: str) -> Tuple[str, Dict[str, str]]:
""" """
Escape(text) Escape(text)
text = Basic.week_annotation(text) # 移除弱注释 text = Basic.week_annotation(text) # 移除弱注释
text = Syllabus(text)() # 渲染提纲
text, values = Value(text)() # 提取变量并赋值到文本中 text, values = Value(text)() # 提取变量并赋值到文本中
text = Header(text)() # 渲染标题 text = Header(text)() # 渲染标题
Syllabus(text)()
text = Style(text)() # 渲染字体样式 text = Style(text)() # 渲染字体样式
text = Function(text)() # 渲染特殊功能 text = Function(text)() # 渲染特殊功能
text = Cite(text)() # 渲染引用 text = Cite(text)() # 渲染引用