From 2c796e7146066873287aa8b7331e26aa150b8030 Mon Sep 17 00:00:00 2001 From: crossdark Date: Tue, 1 Oct 2024 20:56:31 +0800 Subject: [PATCH] =?UTF-8?q?1.0.4=E5=8F=98=E9=87=8F=E6=9C=89=E4=BA=9B?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CrossDown/Core.py | 15 +++++++++------ CrossDown/Extra.py | 3 +++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CrossDown/Core.py b/CrossDown/Core.py index 6683f38..cf04512 100644 --- a/CrossDown/Core.py +++ b/CrossDown/Core.py @@ -27,6 +27,13 @@ Extensions = { } +try: # 检测当前平台是否支持扩展语法 + import Extra + Extensions += Extra.EXTRA +except ModuleNotFoundError: + EXTRA_ABLE = False + + class Style(Preprocessor): """ 渲染字体样式 @@ -105,15 +112,11 @@ class Value(Preprocessor): def run(self, lines: List[str]) -> List[str]: values = { # 从text中提取所有变量并转换成字典 key: value for key, value in [ - (lambda match: match.groups() if match is not None else ('', '')) # 未定义变量的行统一返回('', '') + (lambda match: match.groups() if match is not None else ('\1', '\2')) # 未定义变量的行统一返回('', '') (re.match(r'\{([^{}#]+)} ?= ?(.+?)(?=\n|$)', line)) for line in lines ] } - anchor = [ - re.match(r'\{#([^{}#]+)}', line) for line in lines - ] - print(anchor) - return lines + return [re.sub(line, values[line], line) if any(value in line for value in values) in values.keys() else line for line in lines] # TODO class Header(Treeprocessor): diff --git a/CrossDown/Extra.py b/CrossDown/Extra.py index e69de29..45f343c 100644 --- a/CrossDown/Extra.py +++ b/CrossDown/Extra.py @@ -0,0 +1,3 @@ +EXTRA = [ + +]