3.4.7 简化了单行代码的格式,去除了{}
This commit is contained in:
parent
e8c8d5b530
commit
ac7826afe6
@ -192,24 +192,21 @@ class InlineCode:
|
|||||||
self.variable = variable
|
self.variable = variable
|
||||||
|
|
||||||
def __call__(self, source: str, language: str, css_class: str, md: markdown.core.Markdown): # 自定义的单行代码格式化器
|
def __call__(self, source: str, language: str, css_class: str, md: markdown.core.Markdown): # 自定义的单行代码格式化器
|
||||||
if language != '': # 调用默认格式化函数
|
if language != '': # 字符串已经定义了语言类型
|
||||||
return md.inlinePatterns['backtick'].highlight_code(
|
return md.inlinePatterns['backtick'].highlight_code(
|
||||||
src=source, language=language, classname=css_class,
|
src=source, language=language, classname=css_class,
|
||||||
md=md
|
md=md
|
||||||
)
|
) # 调用默认格式化函数
|
||||||
try: # 尝试拆分字符串
|
|
||||||
sources: tuple[str, str, str, str] = re.compile(r'(\{)([#-]?)(.*?)(})').match(source).groups()
|
match re.compile(r'([#-])?(.*)').match(source).groups(): # 将字符串拆分为(标志, 值)的形式
|
||||||
except AttributeError: # 不符合格式
|
case '#', archer: # 匹配到`#锚点`
|
||||||
return ''
|
|
||||||
match sources:
|
|
||||||
case '{', '#', archer, '}': # 匹配到{#锚点}
|
|
||||||
return f'<span id="{archer}">{archer}</span>'
|
return f'<span id="{archer}">{archer}</span>'
|
||||||
case '{', '-', inline_link, '}': # 匹配到{-行内链接}
|
case '-', inline_link: # 匹配到`-行内链接`
|
||||||
return f'<a href=#{inline_link}>{inline_link}</a>'
|
return f'<a href=#{inline_link}>{inline_link}</a>'
|
||||||
case '{', '', variable, '}': # 匹配到{变量}
|
case None, variable: # 可能匹配到`变量`
|
||||||
if variable in self.variable:
|
if variable in self.variable: # 是`变量`
|
||||||
return f'<span class="block">{self.variable[variable]}</span>'
|
return f'<span class="block">{self.variable[variable]}</span>'
|
||||||
else:
|
else: # 不是`变量`
|
||||||
return f'<span class="block">{variable}</span>'
|
return f'<span class="block">{variable}</span>'
|
||||||
case _:
|
case _:
|
||||||
return f'<code>{source}</code>'
|
return f'<code>{source}</code>'
|
||||||
|
12
README.html
12
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>
|
||||||
@ -190,18 +190,18 @@
|
|||||||
<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 </h2>
|
<h2 id="4.1">4.1 <span class="block">单行</span></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: .</p>
|
<p>The mock shebang will be treated like text here: <span id="!js var test = 0;">!js var test = 0;</span>.</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> // 不定义范围</p>
|
<p><span class="block">¥y=x*2+1¥</span> // 不定义范围</p>
|
||||||
<p> // 定义了x范围</p>
|
<p><span class="block">¥y=x**2¥€-50,50€</span> // 定义了x范围</p>
|
||||||
<p> // 定义了y范围</p>
|
<p><span class="block">¥y=x**3¥€-50,50|-100,100€</span> // 定义了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>
|
||||||
|
10
README.md
10
README.md
@ -90,11 +90,11 @@ liuhanbo333@icloud.com
|
|||||||
|
|
||||||
3.1 定义
|
3.1 定义
|
||||||
|
|
||||||
`{#锚点}`
|
`#锚点`
|
||||||
|
|
||||||
3.2 链接
|
3.2 链接
|
||||||
|
|
||||||
`{-锚点}`
|
`-锚点`
|
||||||
|
|
||||||
4 代码块
|
4 代码块
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ $\lg\left(\frac{目标生物的理智值}{稳定折磨型工具人的理智值}\
|
|||||||
|
|
||||||
4.1.4 突出
|
4.1.4 突出
|
||||||
|
|
||||||
`{突出内容}`
|
`突出内容`
|
||||||
|
|
||||||
4.2 多行
|
4.2 多行
|
||||||
|
|
||||||
@ -243,7 +243,7 @@ def main():
|
|||||||
|
|
||||||
7..1...4 错误示范
|
7..1...4 错误示范
|
||||||
|
|
||||||
提纲号会被自动配置为锚点,可直接使用`{-7}` `{-7.1}` *这种情况中间必须有间隔*
|
提纲号会被自动配置为锚点,可直接使用`-7` `-7.1` *这种情况中间必须有间隔*
|
||||||
|
|
||||||
8 注释
|
8 注释
|
||||||
|
|
||||||
@ -281,7 +281,7 @@ B
|
|||||||
- b
|
- b
|
||||||
- c
|
- c
|
||||||
|
|
||||||
`{强调变量}`
|
`强调变量`
|
||||||
: - a
|
: - a
|
||||||
- b
|
- b
|
||||||
- c
|
- c
|
||||||
|
Loading…
Reference in New Issue
Block a user