From 2a0785346668fe963d645c168127b56e1398ca9a Mon Sep 17 00:00:00 2001 From: crossdark Date: Sat, 19 Oct 2024 14:31:37 +0800 Subject: [PATCH] =?UTF-8?q?2.1.3=20=E5=AE=8C=E5=96=84=E5=AE=8C=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CrossDown/Core.py | 38 +++++++++++++++++++++++++++++++++++++- setup.py | 2 +- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/CrossDown/Core.py b/CrossDown/Core.py index d9f9668..8fc3ee9 100644 --- a/CrossDown/Core.py +++ b/CrossDown/Core.py @@ -304,10 +304,18 @@ class CodeLine(Treeprocessor): """ def __init__(self, variable: Variable): + """ + 初始化 + :param variable: 变量字典 + """ super().__init__() self.variable = variable - def run(self, root): + def run(self, root: xml.etree.ElementTree.Element): + """ + 渲染 + :param root: Element树 + """ for code in root.findall('.//code'): # 在所有段落中查找单行代码 if re.match(r'\$[^$]*\$', code.text): # 渲染Latex code.text = fr'\({code.text[1:-1]}\)' @@ -345,10 +353,18 @@ class CodeLine(Treeprocessor): class Pre(Extension): """预处理""" def __init__(self, variable: Variable): + """ + 初始化 + :param variable: 变量字典 + """ super().__init__() self.variable = variable def extendMarkdown(self, md: Markdown): + """ + 添加扩展 + :param md: 转换器 + """ md.registerExtension(self) # 注册扩展 md.preprocessors.register(PreProcess(self.variable), 'pre_process', 0) @@ -359,6 +375,10 @@ class Basic(Extension): """ def extendMarkdown(self, md: Markdown): + """ + 添加扩展 + :param md: 转换器 + """ md.registerExtension(self) # 注册扩展 md.inlinePatterns.register(Simple(r'~~(.*?)~~', tag='s'), 'strikethrough', 176) # ~~删除线~~ md.inlinePatterns.register(Simple(r'~(.*?)~', tag='u'), 'underline', 177) # ~下划线~ @@ -379,6 +399,10 @@ class Box(Extension): """ def extendMarkdown(self, md): + """ + 添加扩展 + :param md: 转换器 + """ md.registerExtension(self) # 注册扩展 # 红框警告 md.inlinePatterns.register(ID( @@ -415,6 +439,10 @@ class Box(Extension): class Anchor(Extension): def extendMarkdown(self, md: Markdown): + """ + 添加扩展 + :param md: 转换器 + """ md.registerExtension(self) # 注册扩展 md.inlinePatterns.register(_Anchor(r'\{#([^{}#]+)}'), 'anchor', 0) # 定义锚点 md.inlinePatterns.register(LinkLine(r'\{([^{}#]+)}'), 'line_link', 0) # 添加页内链接 @@ -422,10 +450,18 @@ class Anchor(Extension): class Code(Extension): def __init__(self, variable: Variable): + """ + 初始化 + :param variable: 变量字典 + """ super().__init__() self.variable = variable def extendMarkdown(self, md: Markdown): + """ + 添加扩展 + :param md: 转换器 + """ md.registerExtension(self) # 注册扩展 md.treeprocessors.register(CodeLine(variable=self.variable), 'code_line', 0) # 渲染单行代码块 diff --git a/setup.py b/setup.py index e7f8a29..7b0fcae 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r") as fh: setuptools.setup( name="CrossDown", - version="2.1.2", + version="2.1.3", author="CrossDark", author_email="liuhanbo333@icloud.com", description="CrossDark's MarkDown",