3.4.5 更新match-case
This commit is contained in:
parent
fefa0ad1b5
commit
890b5d8c33
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
import xml
|
import xml
|
||||||
|
|
||||||
from typing import *
|
from typing import *
|
||||||
|
|
||||||
import markdown.core
|
import markdown.core
|
||||||
@ -59,8 +60,8 @@ class Simple(InlineProcessor):
|
|||||||
super().__init__(pattern)
|
super().__init__(pattern)
|
||||||
self.tag = tag
|
self.tag = tag
|
||||||
|
|
||||||
def handleMatch(self, m: Match[str], data: str) -> (Tuple[xml.etree.ElementTree.Element, int, int] |
|
def handleMatch(self, m: Match[str], data: str) -> (tuple[xml.etree.ElementTree.Element, int, int] |
|
||||||
Tuple[None, None, None]):
|
tuple[None, None, None]):
|
||||||
"""
|
"""
|
||||||
处理匹配
|
处理匹配
|
||||||
:param m: re模块的匹配对象
|
:param m: re模块的匹配对象
|
||||||
@ -89,8 +90,8 @@ class Nest(InlineProcessor):
|
|||||||
self.outer_tag = outer_tag
|
self.outer_tag = outer_tag
|
||||||
self.inner_tag = inner_tag
|
self.inner_tag = inner_tag
|
||||||
|
|
||||||
def handleMatch(self, m: Match[str], data: str) -> (Tuple[xml.etree.ElementTree.Element, int, int] |
|
def handleMatch(self, m: Match[str], data: str) -> (tuple[xml.etree.ElementTree.Element, int, int] |
|
||||||
Tuple[None, None, None]):
|
tuple[None, None, None]):
|
||||||
"""
|
"""
|
||||||
处理匹配
|
处理匹配
|
||||||
:param m: re模块的匹配对象
|
:param m: re模块的匹配对象
|
||||||
@ -123,8 +124,8 @@ class ID(InlineProcessor):
|
|||||||
self.property = property_
|
self.property = property_
|
||||||
self.value = value
|
self.value = value
|
||||||
|
|
||||||
def handleMatch(self, m: Match[str], data: str) -> (Tuple[xml.etree.ElementTree.Element, int, int] |
|
def handleMatch(self, m: Match[str], data: str) -> (tuple[xml.etree.ElementTree.Element, int, int] |
|
||||||
Tuple[None, None, None]):
|
tuple[None, None, None]):
|
||||||
"""
|
"""
|
||||||
处理匹配
|
处理匹配
|
||||||
:param m: re模块的匹配对象
|
:param m: re模块的匹配对象
|
||||||
@ -151,7 +152,7 @@ class Syllabus(BlockProcessor):
|
|||||||
"""
|
"""
|
||||||
return re.match(self.syllabus_re, block)
|
return re.match(self.syllabus_re, block)
|
||||||
|
|
||||||
def run(self, parent: xml.etree.ElementTree.Element, blocks: List[str]) -> bool | None:
|
def run(self, parent: xml.etree.ElementTree.Element, blocks: list[str]) -> bool | None:
|
||||||
"""
|
"""
|
||||||
对匹配到的块进行处理
|
对匹配到的块进行处理
|
||||||
:param parent: 当前块的Element对象
|
:param parent: 当前块的Element对象
|
||||||
@ -196,19 +197,20 @@ class InlineCode:
|
|||||||
src=source, language=language, classname=css_class,
|
src=source, language=language, classname=css_class,
|
||||||
md=md
|
md=md
|
||||||
)
|
)
|
||||||
match tuple(source):
|
try: # 尝试拆分字符串
|
||||||
case '{', '#', *archers, '}': # 匹配到{#锚点}
|
sources: tuple[str, str, str, str] = re.compile(r'(\{)([#-]?)(.*?)(})').match(source).groups()
|
||||||
archer = ''.join(archers)
|
except AttributeError: # 不符合格式
|
||||||
|
return ''
|
||||||
|
match sources:
|
||||||
|
case '{', '#', archer, '}': # 匹配到{#锚点}
|
||||||
return f'<span id="{archer}">{archer}</span>'
|
return f'<span id="{archer}">{archer}</span>'
|
||||||
case '{', '-', *inline_links, '}': # 匹配到{-行内链接}
|
case '{', '-', inline_link, '}': # 匹配到{-行内链接}
|
||||||
inline_link = ''.join(inline_links)
|
|
||||||
return f'<a href=#{inline_link}>{inline_link}</a>'
|
return f'<a href=#{inline_link}>{inline_link}</a>'
|
||||||
case '{', *variables, '}': # 匹配到{变量}
|
case '{', '', variable, '}': # 匹配到{变量}
|
||||||
variable = ''.join(variables)
|
|
||||||
if variable in self.variable:
|
if variable in self.variable:
|
||||||
return self.variable[variable]
|
return f'<span class="block">{self.variable[variable]}</span>'
|
||||||
else:
|
else:
|
||||||
return variable
|
return f'<span class="block">{variable}</span>'
|
||||||
case _:
|
case _:
|
||||||
return f'<code>{source}</code>'
|
return f'<code>{source}</code>'
|
||||||
|
|
||||||
|
19
README.html
19
README.html
@ -65,7 +65,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><a href="#4">4 代码块</a><ul>
|
<li><a href="#4">4 代码块</a><ul>
|
||||||
<li><a href="#4.1">4.1 单行</a><ul>
|
<li><a href="#4.1">4.1</a><ul>
|
||||||
<li><a href="#4.1.1">4.1.1 LaTex</a></li>
|
<li><a href="#4.1.1">4.1.1 LaTex</a></li>
|
||||||
<li><a href="#4.1.2">4.1.2 函数</a></li>
|
<li><a href="#4.1.2">4.1.2 函数</a></li>
|
||||||
<li><a href="#4.1.3">4.1.3 按键风格</a></li>
|
<li><a href="#4.1.3">4.1.3 按键风格</a></li>
|
||||||
@ -174,7 +174,6 @@
|
|||||||
<p><a href="链接地址">链接文本</a></p>
|
<p><a href="链接地址">链接文本</a></p>
|
||||||
<p><a href="https://crossdark.com">CrossDark</a></p>
|
<p><a href="https://crossdark.com">CrossDark</a></p>
|
||||||
<p><a href="https://crossdark.net/">https://crossdark.net/</a></p>
|
<p><a href="https://crossdark.net/">https://crossdark.net/</a></p>
|
||||||
<p><a href="https://crossdark.net/">https://crossdark.net/</a></p>
|
|
||||||
<p><a href="mailto:liuhanbo333@icloud.com">liuhanbo333@icloud.com</a></p>
|
<p><a href="mailto:liuhanbo333@icloud.com">liuhanbo333@icloud.com</a></p>
|
||||||
<h3 id="1.3.2">1.3.2 图片</h3>
|
<h3 id="1.3.2">1.3.2 图片</h3>
|
||||||
<p><img alt="链接图片" src="链接地址" /></p>
|
<p><img alt="链接图片" src="链接地址" /></p>
|
||||||
@ -191,23 +190,23 @@
|
|||||||
<h2 id="3.2">3.2 链接</h2>
|
<h2 id="3.2">3.2 链接</h2>
|
||||||
<p><a href=#锚点>锚点</a></p>
|
<p><a href=#锚点>锚点</a></p>
|
||||||
<h1 id="4">4 代码块</h1>
|
<h1 id="4">4 代码块</h1>
|
||||||
<h2 id="4.1">4.1 <code>单行</code></h2>
|
<h2 id="4.1">4.1 </h2>
|
||||||
<p>Here is some code: <code class="highlight"><span class="kn">import</span> <span class="nn">pymdownx</span><span class="p">;</span> <span class="n">pymdownx</span><span class="o">.</span><span class="n">__version__</span></code>.</p>
|
<p>Here is some code: <code class="highlight"><span class="kn">import</span> <span class="nn">pymdownx</span><span class="p">;</span> <span class="n">pymdownx</span><span class="o">.</span><span class="n">__version__</span></code>.</p>
|
||||||
<p>The mock shebang will be treated like text here: <code>#!js var test = 0;</code>.</p>
|
<p>The mock shebang will be treated like text here: .</p>
|
||||||
<h3 id="4.1.1">4.1.1 LaTex</h3>
|
<h3 id="4.1.1">4.1.1 LaTex</h3>
|
||||||
<p>这是<span class="arithmatex"><span class="MathJax_Preview">CO_2</span><script type="math/tex">CO_2</script></span>二氧化碳,或者可以写成这样CO<sub>2</sub></p>
|
<p>这是<span class="arithmatex"><span class="MathJax_Preview">CO_2</span><script type="math/tex">CO_2</script></span>二氧化碳,或者可以写成这样CO<sub>2</sub></p>
|
||||||
<p>这是<span class="arithmatex"><span class="MathJax_Preview">H_2O</span><script type="math/tex">H_2O</script></span>水,或者写成H<sub>2</sub>O
|
<p>这是<span class="arithmatex"><span class="MathJax_Preview">H_2O</span><script type="math/tex">H_2O</script></span>水,或者写成H<sub>2</sub>O
|
||||||
<sup>3</sup>H<sub>2</sub>O</p>
|
<sup>3</sup>H<sub>2</sub>O</p>
|
||||||
<p><span class="arithmatex"><span class="MathJax_Preview">\lg\left(\frac{目标生物的理智值}{稳定折磨型工具人的理智值}\right)</span><script type="math/tex">\lg\left(\frac{目标生物的理智值}{稳定折磨型工具人的理智值}\right)</script></span></p>
|
<p><span class="arithmatex"><span class="MathJax_Preview">\lg\left(\frac{目标生物的理智值}{稳定折磨型工具人的理智值}\right)</span><script type="math/tex">\lg\left(\frac{目标生物的理智值}{稳定折磨型工具人的理智值}\right)</script></span></p>
|
||||||
<h3 id="4.1.2">4.1.2 函数</h3>
|
<h3 id="4.1.2">4.1.2 函数</h3>
|
||||||
<p><code>¥y=x*2+1¥</code> // 不定义范围</p>
|
<p> // 不定义范围</p>
|
||||||
<p><code>¥y=x**2¥€-50,50€</code> // 定义了x范围</p>
|
<p> // 定义了x范围</p>
|
||||||
<p><code>¥y=x**3¥€-50,50|-100,100€</code> // 定义了y范围</p>
|
<p> // 定义了y范围</p>
|
||||||
<h3 id="4.1.3">4.1.3 按键风格</h3>
|
<h3 id="4.1.3">4.1.3 按键风格</h3>
|
||||||
<p><span class="keys"><kbd class="key-control">Ctrl</kbd><span>+</span><kbd class="key-alt">Alt</kbd><span>+</span><kbd class="key-delete">Del</kbd></span></p>
|
<p><span class="keys"><kbd class="key-control">Ctrl</kbd><span>+</span><kbd class="key-alt">Alt</kbd><span>+</span><kbd class="key-delete">Del</kbd></span></p>
|
||||||
<p><kbd>Enter</kbd></p>
|
<p><kbd>Enter</kbd></p>
|
||||||
<h3 id="4.1.4">4.1.4 突出</h3>
|
<h3 id="4.1.4">4.1.4 突出</h3>
|
||||||
<p>突出内容</p>
|
<p><span class="block">突出内容</span></p>
|
||||||
<h2 id="4.2">4.2 多行</h2>
|
<h2 id="4.2">4.2 多行</h2>
|
||||||
<h3 id="4.2.1">4.2.1 YAML</h3>
|
<h3 id="4.2.1">4.2.1 YAML</h3>
|
||||||
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">2</span>
|
<div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal">2</span>
|
||||||
@ -314,7 +313,7 @@
|
|||||||
<p>7.1.3. 错误示范</p>
|
<p>7.1.3. 错误示范</p>
|
||||||
<p>不能出现两个及以上连续的点,例如:</p>
|
<p>不能出现两个及以上连续的点,例如:</p>
|
||||||
<p>7..1...4 错误示范</p>
|
<p>7..1...4 错误示范</p>
|
||||||
<p>提纲号会被自动配置为锚点,可直接使用{-7}{-7.1}</p>
|
<p>提纲号会被自动配置为锚点,可直接使用<a href=#7>7</a> <a href=#7.1>7.1</a> <em>这种情况中间必须有间隔</em></p>
|
||||||
<h1 id="8">8 注释</h1>
|
<h1 id="8">8 注释</h1>
|
||||||
<!-- 这是注释 -->
|
<!-- 这是注释 -->
|
||||||
|
|
||||||
@ -355,7 +354,7 @@
|
|||||||
<li>c</li>
|
<li>c</li>
|
||||||
</ul>
|
</ul>
|
||||||
</dd>
|
</dd>
|
||||||
<dt>强调值</dt>
|
<dt><span class="block">强调值</span></dt>
|
||||||
<dd>
|
<dd>
|
||||||
<ul>
|
<ul>
|
||||||
<li>a</li>
|
<li>a</li>
|
||||||
|
@ -60,8 +60,6 @@ ___
|
|||||||
|
|
||||||
[CrossDark](https://crossdark.com)
|
[CrossDark](https://crossdark.com)
|
||||||
|
|
||||||
<https://crossdark.net/>
|
|
||||||
|
|
||||||
https://crossdark.net/
|
https://crossdark.net/
|
||||||
|
|
||||||
liuhanbo333@icloud.com
|
liuhanbo333@icloud.com
|
||||||
@ -245,7 +243,7 @@ def main():
|
|||||||
|
|
||||||
7..1...4 错误示范
|
7..1...4 错误示范
|
||||||
|
|
||||||
提纲号会被自动配置为锚点,可直接使用{-7}{-7.1}
|
提纲号会被自动配置为锚点,可直接使用`{-7}` `{-7.1}` *这种情况中间必须有间隔*
|
||||||
|
|
||||||
8 注释
|
8 注释
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user