From b4d4fff952fccbb4f372658487c28d8d923d0a71 Mon Sep 17 00:00:00 2001 From: crossdark Date: Tue, 19 Nov 2024 19:27:42 +0800 Subject: [PATCH] =?UTF-8?q?3.4.1=20emm=E8=87=AA=E5=AE=9A=E4=B9=89InlineHil?= =?UTF-8?q?ite=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CrossDown/Core.py | 19 ++++++++++++------- README.html | 8 ++++---- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CrossDown/Core.py b/CrossDown/Core.py index 483e2a5..61841ce 100644 --- a/CrossDown/Core.py +++ b/CrossDown/Core.py @@ -275,15 +275,20 @@ class CodeExtension(Extension): md.treeprocessors.register(CodeLine(variable=self.variable), 'code_line', 100) -def variable_formatter(source, language, css_class, md): - if language != '': - return InlineHilitePattern.highlight_code(src=source, language=language, classname=css_class, md=md) +def inline_formatter(source, language, css_class, md): # 自定义的单行代码格式化器 + if language != '': # 调用默认格式化函数 + return md.inlinePatterns['backtick'].highlight_code(src=source, language=language, classname=css_class, md=md) match tuple(source): case '{', '#', *archers, '}': # 匹配到{#锚点} - archer = str(archers.items()) + archer = ''.join(archers) return f'{archer}' + case '{', '-', *inline_links, '}': # 匹配到{-行内链接} + inline_link = ''.join(inline_links) + return f'{inline_link}' + case '{', *variable, '}': # 匹配到{变量} + return ''.join(variable) case _: - return f'{source}' # Or string + return f'{source}' Extensions = { @@ -319,7 +324,7 @@ Extensions = { { 'name': '*', 'class': 'block', - 'format': variable_formatter, + 'format': inline_formatter, }, ] ), @@ -341,7 +346,7 @@ Extensions = { # 自定义 '基本风格': BasicExtension(), - '锚点': AnchorExtension(), + # '锚点': AnchorExtension(), } diff --git a/README.html b/README.html index b0ffd39..0678995 100644 --- a/README.html +++ b/README.html @@ -187,12 +187,12 @@

直接在文本中使用 缩写 即可

3 锚点

3.1 定义

-

`锚点`

+

锚点

3.2 链接

-

{-锚点}

+

锚点

4 代码块

4.1 单行

-

Here is some code: `#!py3 import pymdownx; pymdownx.version`.

+

Here is some code: import pymdownx; pymdownx.__version__.

The mock shebang will be treated like text here: #!js var test = 0;.

4.1.1 LaTex

这是CO_2二氧化碳,或者可以写成这样CO2

@@ -314,7 +314,7 @@

7.1.3. 错误示范

不能出现两个及以上连续的点,例如:

7..1...4 错误示范

-

提纲号会被自动配置为锚点,可直接使用77.1

+

提纲号会被自动配置为锚点,可直接使用{-7}{-7.1}

8 注释