forked from CrossDark/CrossDown
1.6提醒制作中
This commit is contained in:
parent
97fe6ed5bd
commit
235d922883
@ -158,25 +158,28 @@ class Syllabus(BlockProcessor):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class BoxBlockProcessor(BlockProcessor):
|
class BoxBlock(BlockProcessor):
|
||||||
RE_FENCE_START = r'^ *!{3,} *\n' # start line, e.g., ` !!!! `
|
def __init__(self, parser, re_start, re_end, style):
|
||||||
RE_FENCE_END = r'\n *!{3,}\s*$' # last non-blank line, e.g, '!!!\n \n\n'
|
super().__init__(parser)
|
||||||
|
self.re_start = re_start # start line, e.g., ` !!!!
|
||||||
|
self.re_end = re_end # last non-blank line, e.g, '!!!\n \n\n'
|
||||||
|
self.style = style
|
||||||
|
|
||||||
def test(self, parent, block):
|
def test(self, parent, block):
|
||||||
return re.match(self.RE_FENCE_START, block)
|
return re.match(self.re_start, block)
|
||||||
|
|
||||||
def run(self, parent, blocks):
|
def run(self, parent, blocks):
|
||||||
original_block = blocks[0]
|
original_block = blocks[0]
|
||||||
blocks[0] = re.sub(self.RE_FENCE_START, '', blocks[0])
|
blocks[0] = re.sub(self.re_start, '', blocks[0])
|
||||||
|
|
||||||
# Find block with ending fence
|
# Find block with ending fence
|
||||||
for block_num, block in enumerate(blocks):
|
for block_num, block in enumerate(blocks):
|
||||||
if re.search(self.RE_FENCE_END, block):
|
if re.search(self.re_end, block):
|
||||||
# remove fence
|
# remove fence
|
||||||
blocks[block_num] = re.sub(self.RE_FENCE_END, '', block)
|
blocks[block_num] = re.sub(self.re_end, '', block)
|
||||||
# render fenced area inside a new div
|
# render fenced area inside a new div
|
||||||
e = xml.etree.ElementTree.SubElement(parent, 'div')
|
e = xml.etree.ElementTree.SubElement(parent, 'div')
|
||||||
e.set('style', 'display: inline-block; border: 1px solid red;')
|
e.set('style', self.style)
|
||||||
self.parser.parseBlocks(e, blocks[0:block_num + 1])
|
self.parser.parseBlocks(e, blocks[0:block_num + 1])
|
||||||
# remove used blocks
|
# remove used blocks
|
||||||
for i in range(0, block_num + 1):
|
for i in range(0, block_num + 1):
|
||||||
@ -214,7 +217,14 @@ class Box(Extension):
|
|||||||
|
|
||||||
def extendMarkdown(self, md):
|
def extendMarkdown(self, md):
|
||||||
md.registerExtension(self) # 注册扩展
|
md.registerExtension(self) # 注册扩展
|
||||||
md.parser.blockprocessors.register(BoxBlockProcessor(md.parser), 'box', 175)
|
# 红框警告
|
||||||
|
md.parser.blockprocessors.register(BoxBlock(
|
||||||
|
md.parser, r'^ *!{3,} *\n', r'\n *!{3,}\s*$', 'display: inline-block; border: 1px solid red;'
|
||||||
|
), 'warning_box', 175) # 块
|
||||||
|
# 黄框提醒
|
||||||
|
md.parser.blockprocessors.register(BoxBlock(
|
||||||
|
md.parser, r'^ *!{2,} *\n', r'\n *!{2,}\s*$', 'display: inline-block; border: 1px solid yellow;'
|
||||||
|
), 'reminding_box', 175)
|
||||||
|
|
||||||
|
|
||||||
def main(text: str) -> Tuple[str, Dict[str, List[str]]]:
|
def main(text: str) -> Tuple[str, Dict[str, List[str]]]:
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>UTF-8编码示例</title>
|
<title>UTF-8编码示例</title>
|
||||||
<link href="style.css" rel="stylesheet" />
|
|
||||||
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML"></script>
|
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML"></script>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/prismjs/themes/prism.css" rel="stylesheet" />
|
<link href="https://cdn.jsdelivr.net/npm/prismjs/themes/prism.css" rel="stylesheet" />
|
||||||
<script src="https://cdn.jsdelivr.net/npm/prismjs/prism.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/prismjs/prism.js"></script>
|
||||||
@ -119,6 +118,7 @@
|
|||||||
</li>
|
</li>
|
||||||
<li><a href="#14">14 外框</a><ul>
|
<li><a href="#14">14 外框</a><ul>
|
||||||
<li><a href="#14.1">14.1 警告</a></li>
|
<li><a href="#14.1">14.1 警告</a></li>
|
||||||
|
<li><a href="#14.2">14.2 提醒</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -299,5 +299,9 @@
|
|||||||
<div style="display: inline-block; border: 1px solid red;">
|
<div style="display: inline-block; border: 1px solid red;">
|
||||||
<p>这是一条警告</p>
|
<p>这是一条警告</p>
|
||||||
</div>
|
</div>
|
||||||
|
<h2 id="14.2">14.2 提醒</h2>
|
||||||
|
<div style="display: inline-block; border: 1px solid yellow;">
|
||||||
|
<p>这是一条提醒</p>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -251,3 +251,9 @@ graph LR
|
|||||||
!!!
|
!!!
|
||||||
这是一条警告
|
这是一条警告
|
||||||
!!!
|
!!!
|
||||||
|
|
||||||
|
14.2 提醒
|
||||||
|
|
||||||
|
!!
|
||||||
|
这是一条提醒
|
||||||
|
!!
|
||||||
|
1
run.py
1
run.py
@ -17,7 +17,6 @@ if __name__ == '__main__':
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>UTF-8编码示例</title>
|
<title>UTF-8编码示例</title>
|
||||||
<link href="style.css" rel="stylesheet" />
|
|
||||||
{indent(HEAD)}
|
{indent(HEAD)}
|
||||||
<!-- 可以在这里添加其他元数据和CSS链接 -->
|
<!-- 可以在这里添加其他元数据和CSS链接 -->
|
||||||
</head>
|
</head>
|
||||||
|
Loading…
Reference in New Issue
Block a user