diff --git a/CrossDown.py b/CrossDown.py index ec78c02..3ee2f18 100644 --- a/CrossDown.py +++ b/CrossDown.py @@ -165,10 +165,12 @@ class CodeBlock: head = re.findall(r'(.*?)\n', code)[0] if head in ('', 'yaml'): self.codes[index] = f'
{code}
'
- elif head == 'shell':
- pass
- elif re.match(r'\$[^$]*\$', code): # 是LaTex代码
- self.codes[index] = re.sub(fr'\$([^$]*)\$', r'\(\1\)', code)
+ elif head in ('shell', 'python'):
+ self.codes[index] = f'{re.sub(f"({head})[s/S]*?", "", code)}
'
+ elif re.match(r'\$[^$]*\$', code): # 是LaTex代码(单行)
+ self.codes[index] = re.sub(fr'\$([^$]*)\$', r'\(\1\)
', code) + else: # 是突出块 + self.codes[index] = f'{code}' def restore(self, new_text: str): """ @@ -232,10 +234,9 @@ class Basic: r'\1\n', # 移除已被标签包裹的行的额外的标签 '\n'.join( [ - f'
{line}
' for line in self.text.splitlines() if - not re.search( # 把所有非空的行都套上标签 - r'^\s*\n?$', line # 识别空行或空白行 TODO 还应识别-@@-n-@@- - ) + f'
{line}
' if not re.search(r'-@@-.+?-@@-', line) else line # 识别-@@-n-@@-并保留 + for line in self.text.splitlines() # 把所有非空的行都套上标签 + if not re.search(r'^\s*\n?$', line) # 识别空行或空白行 ] ) ) @@ -301,7 +302,15 @@ if __name__ == '__main__': + + +