1.9.4 代码块升级

This commit is contained in:
跨越晨昏 2024-10-16 19:24:51 +08:00
parent 9ef3a6669b
commit 60913d787d
3 changed files with 97 additions and 39 deletions

View File

@ -10,12 +10,13 @@ from markdown.blockprocessors import BlockProcessor
from markdown import Markdown from markdown import Markdown
from typing import * from typing import *
import re import re
import lxml
import xml import xml
import emoji import emoji
try: # 检测当前平台是否支持扩展语法 try: # 检测当前平台是否支持扩展语法
from .Extra import * from .Extra import *
EXTRA_ABLE = True EXTRA_ABLE = True
except ModuleNotFoundError: # 不支持扩展语法 except ModuleNotFoundError: # 不支持扩展语法
EXTRA_ABLE = False EXTRA_ABLE = False
@ -206,15 +207,15 @@ class CodeLine(Treeprocessor):
self.variable = variable self.variable = variable
def run(self, root): def run(self, root):
for elem in root.iter('p'): # 在所有段落中查找单行代码 for code in root.findall('.//code'): # 在所有段落中查找单行代码
if elem.findall('code'): # 找到单行代码
for code in elem:
if re.match(r'\$[^$]*\$', code.text): # 渲染Latex if re.match(r'\$[^$]*\$', code.text): # 渲染Latex
if isinstance(elem.text, str): # 这个段落还有其它内容 code.text = fr'\({code.text[1:-1]}\)'
code.tag = 'p'
"""if isinstance(elem.text, str): # 这个段落还有其它内容
elem.text += fr'\({code.text[1:-1]}\){code.tail}' # 插入latex elem.text += fr'\({code.text[1:-1]}\){code.tail}' # 插入latex
else: else:
elem.text = fr'\({code.text[1:-1]}\)' # latex是段落中唯一的内容 elem.text = fr'\({code.text[1:-1]}\)' # latex是段落中唯一的内容
elem.remove(code) elem.remove(code)"""
elif re.match(r'¥[^$]*¥', code.text): # 是数学函数(单行) elif re.match(r'¥[^$]*¥', code.text): # 是数学函数(单行)
if EXTRA_ABLE: # 支持扩展语法 if EXTRA_ABLE: # 支持扩展语法
expression, range_ = re.findall(r'¥([^$]*)¥(€[^$]*€)?', code.text)[0] # 分离表达式与范围(如果有) expression, range_ = re.findall(r'¥([^$]*)¥(€[^$]*€)?', code.text)[0] # 分离表达式与范围(如果有)

File diff suppressed because one or more lines are too long

View File

@ -252,6 +252,30 @@ cd ../..
- C - C
- D - D
9.3 释义列表
A
: 1. a
2. b
3. c
B
: - a
- b
- c
`{强调变量}`
: - a
- b
- c
Apple
: Pomaceous fruit of plants of the genus Malus in
the family Rosaceae.
Orange
: The fruit of an evergreen tree of the genus Citrus.
10 表格 10 表格
| 表头1 | 表头2 | 表头3 | | 表头1 | 表头2 | 表头3 |