2.1.3 完善完了
This commit is contained in:
parent
2c04390756
commit
2a07853466
@ -304,10 +304,18 @@ class CodeLine(Treeprocessor):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, variable: Variable):
|
def __init__(self, variable: Variable):
|
||||||
|
"""
|
||||||
|
初始化
|
||||||
|
:param variable: 变量字典
|
||||||
|
"""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.variable = variable
|
self.variable = variable
|
||||||
|
|
||||||
def run(self, root):
|
def run(self, root: xml.etree.ElementTree.Element):
|
||||||
|
"""
|
||||||
|
渲染
|
||||||
|
:param root: Element树
|
||||||
|
"""
|
||||||
for code in root.findall('.//code'): # 在所有段落中查找单行代码
|
for code in root.findall('.//code'): # 在所有段落中查找单行代码
|
||||||
if re.match(r'\$[^$]*\$', code.text): # 渲染Latex
|
if re.match(r'\$[^$]*\$', code.text): # 渲染Latex
|
||||||
code.text = fr'\({code.text[1:-1]}\)'
|
code.text = fr'\({code.text[1:-1]}\)'
|
||||||
@ -345,10 +353,18 @@ class CodeLine(Treeprocessor):
|
|||||||
class Pre(Extension):
|
class Pre(Extension):
|
||||||
"""预处理"""
|
"""预处理"""
|
||||||
def __init__(self, variable: Variable):
|
def __init__(self, variable: Variable):
|
||||||
|
"""
|
||||||
|
初始化
|
||||||
|
:param variable: 变量字典
|
||||||
|
"""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.variable = variable
|
self.variable = variable
|
||||||
|
|
||||||
def extendMarkdown(self, md: Markdown):
|
def extendMarkdown(self, md: Markdown):
|
||||||
|
"""
|
||||||
|
添加扩展
|
||||||
|
:param md: 转换器
|
||||||
|
"""
|
||||||
md.registerExtension(self) # 注册扩展
|
md.registerExtension(self) # 注册扩展
|
||||||
md.preprocessors.register(PreProcess(self.variable), 'pre_process', 0)
|
md.preprocessors.register(PreProcess(self.variable), 'pre_process', 0)
|
||||||
|
|
||||||
@ -359,6 +375,10 @@ class Basic(Extension):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def extendMarkdown(self, md: Markdown):
|
def extendMarkdown(self, md: Markdown):
|
||||||
|
"""
|
||||||
|
添加扩展
|
||||||
|
:param md: 转换器
|
||||||
|
"""
|
||||||
md.registerExtension(self) # 注册扩展
|
md.registerExtension(self) # 注册扩展
|
||||||
md.inlinePatterns.register(Simple(r'~~(.*?)~~', tag='s'), 'strikethrough', 176) # ~~删除线~~
|
md.inlinePatterns.register(Simple(r'~~(.*?)~~', tag='s'), 'strikethrough', 176) # ~~删除线~~
|
||||||
md.inlinePatterns.register(Simple(r'~(.*?)~', tag='u'), 'underline', 177) # ~下划线~
|
md.inlinePatterns.register(Simple(r'~(.*?)~', tag='u'), 'underline', 177) # ~下划线~
|
||||||
@ -379,6 +399,10 @@ class Box(Extension):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def extendMarkdown(self, md):
|
def extendMarkdown(self, md):
|
||||||
|
"""
|
||||||
|
添加扩展
|
||||||
|
:param md: 转换器
|
||||||
|
"""
|
||||||
md.registerExtension(self) # 注册扩展
|
md.registerExtension(self) # 注册扩展
|
||||||
# 红框警告
|
# 红框警告
|
||||||
md.inlinePatterns.register(ID(
|
md.inlinePatterns.register(ID(
|
||||||
@ -415,6 +439,10 @@ class Box(Extension):
|
|||||||
|
|
||||||
class Anchor(Extension):
|
class Anchor(Extension):
|
||||||
def extendMarkdown(self, md: Markdown):
|
def extendMarkdown(self, md: Markdown):
|
||||||
|
"""
|
||||||
|
添加扩展
|
||||||
|
:param md: 转换器
|
||||||
|
"""
|
||||||
md.registerExtension(self) # 注册扩展
|
md.registerExtension(self) # 注册扩展
|
||||||
md.inlinePatterns.register(_Anchor(r'\{#([^{}#]+)}'), 'anchor', 0) # 定义锚点
|
md.inlinePatterns.register(_Anchor(r'\{#([^{}#]+)}'), 'anchor', 0) # 定义锚点
|
||||||
md.inlinePatterns.register(LinkLine(r'\{([^{}#]+)}'), 'line_link', 0) # 添加页内链接
|
md.inlinePatterns.register(LinkLine(r'\{([^{}#]+)}'), 'line_link', 0) # 添加页内链接
|
||||||
@ -422,10 +450,18 @@ class Anchor(Extension):
|
|||||||
|
|
||||||
class Code(Extension):
|
class Code(Extension):
|
||||||
def __init__(self, variable: Variable):
|
def __init__(self, variable: Variable):
|
||||||
|
"""
|
||||||
|
初始化
|
||||||
|
:param variable: 变量字典
|
||||||
|
"""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.variable = variable
|
self.variable = variable
|
||||||
|
|
||||||
def extendMarkdown(self, md: Markdown):
|
def extendMarkdown(self, md: Markdown):
|
||||||
|
"""
|
||||||
|
添加扩展
|
||||||
|
:param md: 转换器
|
||||||
|
"""
|
||||||
md.registerExtension(self) # 注册扩展
|
md.registerExtension(self) # 注册扩展
|
||||||
md.treeprocessors.register(CodeLine(variable=self.variable), 'code_line', 0) # 渲染单行代码块
|
md.treeprocessors.register(CodeLine(variable=self.variable), 'code_line', 0) # 渲染单行代码块
|
||||||
|
|
||||||
|
2
setup.py
2
setup.py
@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="CrossDown",
|
name="CrossDown",
|
||||||
version="2.1.2",
|
version="2.1.3",
|
||||||
author="CrossDark",
|
author="CrossDark",
|
||||||
author_email="liuhanbo333@icloud.com",
|
author_email="liuhanbo333@icloud.com",
|
||||||
description="CrossDark's MarkDown",
|
description="CrossDark's MarkDown",
|
||||||
|
Loading…
Reference in New Issue
Block a user