diff --git a/CrossDown/Core.py b/CrossDown/Core.py index d70c279..47b151f 100644 --- a/CrossDown/Core.py +++ b/CrossDown/Core.py @@ -120,7 +120,6 @@ class Value(Preprocessor): for key, value in [match.groups()] } # 识别变量定义 anchors = re.findall(r'\{#([^{}#]+)}', '\n'.join(lines)) # 识别锚点定义 - print(anchors) for index, line in enumerate(lines): if any(value in line for value in values): # 匹配到了变量 for key, value in values.items(): @@ -132,7 +131,11 @@ class Value(Preprocessor): if re.search('\{#', line): # 是锚点定义 lines[index] = re.sub(r'\{#(.+)}', r'', line) # 定义锚点 else: # 是页内链接 - print(line) + lines[index] = re.sub(r'\{#' + + (lambda x: x if x in anchors else '\0') # 识别ID是否为锚点 + ((lambda x: x[0] if x is not None else '\0') # 排除匹配不成功的情况 + (re.search(r'\{#(.+)}', line))) + '}', # 匹配链接id + r'\1', line) # 添加页内链接 return lines diff --git a/README.html b/README.html index 1f7f9f6..c2cb4ae 100644 --- a/README.html +++ b/README.html @@ -110,10 +110,7 @@
值 {锚点名}
+{变量名} {锚点名}
提纲的编号已经自动配置为了锚点,可直接使用{2}
@@ -278,9 +275,5 @@
🚴
😃
危险
-