From ac7826afe6809c2bf4b2e2028c9cc2480220292f Mon Sep 17 00:00:00 2001 From: crossdark Date: Sun, 24 Nov 2024 17:51:05 +0800 Subject: [PATCH] =?UTF-8?q?3.4.7=20=E7=AE=80=E5=8C=96=E4=BA=86=E5=8D=95?= =?UTF-8?q?=E8=A1=8C=E4=BB=A3=E7=A0=81=E7=9A=84=E6=A0=BC=E5=BC=8F,?= =?UTF-8?q?=E5=8E=BB=E9=99=A4=E4=BA=86{}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CrossDown/Core.py | 21 +++++++++------------ README.html | 12 ++++++------ README.md | 10 +++++----- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/CrossDown/Core.py b/CrossDown/Core.py index a82b176..0ecc2e8 100644 --- a/CrossDown/Core.py +++ b/CrossDown/Core.py @@ -192,24 +192,21 @@ class InlineCode: self.variable = variable def __call__(self, source: str, language: str, css_class: str, md: markdown.core.Markdown): # 自定义的单行代码格式化器 - if language != '': # 调用默认格式化函数 + if language != '': # 字符串已经定义了语言类型 return md.inlinePatterns['backtick'].highlight_code( src=source, language=language, classname=css_class, md=md - ) - try: # 尝试拆分字符串 - sources: tuple[str, str, str, str] = re.compile(r'(\{)([#-]?)(.*?)(})').match(source).groups() - except AttributeError: # 不符合格式 - return '' - match sources: - case '{', '#', archer, '}': # 匹配到{#锚点} + ) # 调用默认格式化函数 + + match re.compile(r'([#-])?(.*)').match(source).groups(): # 将字符串拆分为(标志, 值)的形式 + case '#', archer: # 匹配到`#锚点` return f'{archer}' - case '{', '-', inline_link, '}': # 匹配到{-行内链接} + case '-', inline_link: # 匹配到`-行内链接` return f'{inline_link}' - case '{', '', variable, '}': # 匹配到{变量} - if variable in self.variable: + case None, variable: # 可能匹配到`变量` + if variable in self.variable: # 是`变量` return f'{self.variable[variable]}' - else: + else: # 不是`变量` return f'{variable}' case _: return f'{source}' diff --git a/README.html b/README.html index 43684c0..d56f97a 100644 --- a/README.html +++ b/README.html @@ -65,7 +65,7 @@
  • 4 代码块