diff --git a/CrossDown.py b/CrossDown.py index 8dcb044..cd23c4e 100644 --- a/CrossDown.py +++ b/CrossDown.py @@ -160,14 +160,14 @@ class Value: """ 定义: {变量名} = 值 赋值: {变量或锚点名} - 锚点: #{锚点名} + 锚点: {#锚点名} """ def __init__(self, text: str): self.text = text self.values = { key: value for key, value in re.findall(r'\{([^{}#]+)} ?= ?(.+?)(?=\n|$)', text) } # 从text中提取所有变量并转换成字典 - self.anchor = re.findall(r'#\{([^{}]+)}', text) # TODO + self.anchor = re.findall(r'\{#([^{}#]+)}', text) def __call__(self, *args, **kwargs) -> Tuple[str, Dict[str, str]]: """ @@ -178,7 +178,7 @@ class Value: """ text = self.text for item in self.anchor: - text = re.sub(r'#\{(' + item + ')}', r'', text) # 添加锚点 + text = re.sub(r'\{#(' + item + ')}', r'', text) # 添加锚点 text = re.sub(r'\{' + item + '}', fr'{item}', text) # 添加页内链接 for k, v in self.values.items(): text = re.sub(r'\{' + k + '} ?= ?(.+?)(?=\n|$)', '', text) # 移除变量的定义 @@ -242,7 +242,7 @@ class CodeBlock: return new_text -class Escape: +class Escape: # TODO 还有点问题 """ 转义\后字符 """ @@ -264,7 +264,6 @@ class Escape: :param kwargs: :return: 不含代码的文本 """ - # TODO for index, item in self.escapes.items(): # 替换代码块为\0\1\2(id)\2\1\0 self.text = re.sub(fr'{re.escape(index)}', item, self.text) # 同时转译特殊字符 print(item) @@ -315,7 +314,7 @@ class Syllabus: def __call__(self, *args, **kwargs): for num, txt in self.syllabus.items(): - self.text = re.sub(f'{".".join(num)} {re.escape(txt)}', f'{".".join(num)} {txt}#{{' + '.'.join(num) + f'}}', self.text) # 按照层级为提纲添加不同等级的标题并创建锚点 + self.text = re.sub(f'{".".join(num)} {re.escape(txt)}', f'{".".join(num)} {txt}{{#' + '.'.join(num) + f'}}', self.text) # 按照层级为提纲添加不同等级的标题并创建锚点 return self.text diff --git a/README.html b/README.html index d6f6fd2..f8d7c46 100644 Binary files a/README.html and b/README.html differ diff --git a/README.md b/README.md index 1d6ed4e..a67659c 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ ___ 2.2 赋值 {变量名} {锚点名} 2.3 添加锚点 -#{锚点名} +{#锚点名} 3 代码块 3.1 `单行` 3.1.1 LaTex @@ -64,7 +64,9 @@ graph LR C-->D ` 4 转义 -\\ +\\ +\a +\* 5 引用 > 渲染引用 --[引用来源] 6 提纲