1.3变量头疼中

This commit is contained in:
跨越晨昏 2024-10-03 22:03:47 +08:00
parent 5bf956833b
commit aa42d52b9c
3 changed files with 13 additions and 22 deletions

View File

@ -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'<span id="\1"></span>', 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'<a href="#\1">\1</a>', line) # 添加页内链接
return lines

View File

@ -110,10 +110,7 @@
<li><a href="#9">9 表格</a></li>
<li><a href="#10">10 警告</a></li>
<li><a href="#11">11 Emoji</a></li>
<li><a href="#12">12 扩展语法</a><ul>
<li><a href="#12.1">12.1 警告</a></li>
</ul>
</li>
<li><a href="#12">12 扩展语法</a></li>
</ul>
</div>
<h1 id="CrossDown">CrossDown</h1>
@ -153,7 +150,7 @@
<h1 id="2">2 变量</h1>
<h2 id="2.1">2.1 定义</h2>
<h2 id="2.2">2.2 赋值</h2>
<p> {锚点名}</p>
<p>{变量名} {锚点名}</p>
<p>提纲的编号已经自动配置为了锚点,可直接使用{2}</p>
<h2 id="2.3">2.3 添加锚点</h2>
<p><span id="锚点名"></span></p>
@ -278,9 +275,5 @@
<p>🚴</p>
<p>😃</p>
<h1 id="12">12 扩展语法</h1>
<h2 id="12.1">12.1 警告</h2>
<div class="admonition 危险">
<p class="admonition-title">危险</p>
</div>
</body>
</html>

View File

@ -1,10 +1,9 @@
Title: My Document
Summary: A brief description of my document.
Authors: Waylan Limberg
John Doe
Date: October 2, 2007
blank-value:
base_url: http://example.com
Title: CrossDown示例
Summary: 够简洁的了
Authors: CrossDark
Date: __date__
blank-value: g
base_url: http://crossdark.net:3000/crossdark/CrossDown
[TOC]
@ -226,7 +225,3 @@ graph LR
:grinning_face_with_big_eyes:
12 扩展语法
12.1 警告
!!! 危险