From 65503f0ea7ca9110a4de7cfc60c43dd47631903e Mon Sep 17 00:00:00 2001 From: crossdark Date: Sat, 31 Aug 2024 14:20:37 +0800 Subject: [PATCH] =?UTF-8?q?V0.4.1,=E6=94=B9=E5=AE=8C=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CrossDown.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CrossDown.py b/CrossDown.py index dac4d18..331b703 100644 --- a/CrossDown.py +++ b/CrossDown.py @@ -146,7 +146,7 @@ class CodeBlock: :return: 不含代码的文本 """ for index, item in enumerate(self.codes): # 替换代码块为-@@-(ID)-@@- - self.text = re.sub(fr'`{re.escape(item)}`', f'-@@-{index}-@@-', self.text) # 同时转译特殊字符 + self.text = re.sub(fr'`{re.escape(item)}`', f'\0\1{index}\1\0', self.text) # 同时转译特殊字符 return self.text def rendering(self, values: Dict[str, str]): @@ -179,7 +179,7 @@ class CodeBlock: :return: 加上代码的文章 """ for index, item in enumerate(self.codes): - new_text = re.sub(fr'-@@-{index}-@@-', f'{item}', new_text, flags=re.DOTALL) + new_text = re.sub(f'\0\1{index}\1\0', f'{item}', new_text, flags=re.DOTALL) return new_text @@ -195,7 +195,7 @@ class Escape: """ self.text = text self.escapes = { - i: f'-@@-@{i}-@@-' for i in re.findall(r'\\(.)', text) + i: f'\0\1\2{i}\2\1\0' for i in re.findall(r'\\(.)', text) } # 找出要转义的字符 print(self.escapes) @@ -208,7 +208,7 @@ class Escape: """ # TODO for index, item in enumerate(self.escapes): # 替换代码块为-@@-(ID)-@@- - self.text = re.sub(fr'{index}', f'-@@-@{index}-@@-', self.text) # 同时转译特殊字符 + self.text = re.sub(fr'{index}', f'\0\1\2{index}\2\1\0', self.text) # 同时转译特殊字符 return self.text def restore(self, new_text: str): @@ -263,7 +263,7 @@ class Basic: r'\1\n', # 移除已被标签包裹的行的额外的

标签 '\n'.join( [ - f'

{line}

' if not re.search(r'-@@-.+?-@@-', line) else line # 识别-@@-n-@@-并保留 + f'

{line}

' if not re.search('\0.+?\0', line) else line # 识别-@@-n-@@-并保留 for line in self.text.splitlines() # 把所有非空的行都套上

标签 if not re.search(r'^\s*\n?$', line) # 识别空行或空白行 ]