From a11153182abcd3c2b0dd6583d24f44dd383582a0 Mon Sep 17 00:00:00 2001 From: crossdark Date: Sun, 8 Sep 2024 22:22:30 +0800 Subject: [PATCH] =?UTF-8?q?V0.6.1=E8=BD=AC=E4=B9=89=E8=BF=98=E4=B8=8D?= =?UTF-8?q?=E8=A1=8C,=E9=94=9A=E7=82=B9=E5=A5=BD=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CrossDown.py | 11 +++++------ README.html | Bin 3957 -> 3990 bytes README.md | 6 ++++-- 3 files changed, 9 insertions(+), 8 deletions(-) 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 d6f6fd22aa77ee6bd81ee3b9a43cb12460ee866a..f8d7c466ce85c843841be2b804f38f7cd84a1ce3 100644 GIT binary patch delta 47 ocmew=H%)%SRbC|qMy41hMg|2g1t0)&*pWFgT0q|BYrOLr0o3dW0ssI2 delta 14 WcmbOx|5a|oRbIxJ&EI+FGXelGPzDbG 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 提纲