From 60913d787dd1d76bb336c5f1c54f7365e3cc99c1 Mon Sep 17 00:00:00 2001
From: crossdark
Date: Wed, 16 Oct 2024 19:24:51 +0800
Subject: [PATCH] =?UTF-8?q?1.9.4=20=E4=BB=A3=E7=A0=81=E5=9D=97=E5=8D=87?=
=?UTF-8?q?=E7=BA=A7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
CrossDown/Core.py | 71 ++++++++++++++++++++++++-----------------------
README.html | 41 ++++++++++++++++++++++++---
README.md | 24 ++++++++++++++++
3 files changed, 97 insertions(+), 39 deletions(-)
diff --git a/CrossDown/Core.py b/CrossDown/Core.py
index 7301ec9..11adff5 100644
--- a/CrossDown/Core.py
+++ b/CrossDown/Core.py
@@ -10,12 +10,13 @@ from markdown.blockprocessors import BlockProcessor
from markdown import Markdown
from typing import *
import re
+import lxml
import xml
import emoji
-
try: # 检测当前平台是否支持扩展语法
from .Extra import *
+
EXTRA_ABLE = True
except ModuleNotFoundError: # 不支持扩展语法
EXTRA_ABLE = False
@@ -206,43 +207,43 @@ class CodeLine(Treeprocessor):
self.variable = variable
def run(self, root):
- for elem in root.iter('p'): # 在所有段落中查找单行代码
- if elem.findall('code'): # 找到单行代码
- for code in elem:
- if re.match(r'\$[^$]*\$', code.text): # 渲染Latex
- if isinstance(elem.text, str): # 这个段落还有其它内容
+ for code in root.findall('.//code'): # 在所有段落中查找单行代码
+ if re.match(r'\$[^$]*\$', code.text): # 渲染Latex
+ 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
else:
elem.text = fr'\({code.text[1:-1]}\)' # latex是段落中唯一的内容
- elem.remove(code)
- elif re.match(r'¥[^$]*¥', code.text): # 是数学函数(单行)
- if EXTRA_ABLE: # 支持扩展语法
- expression, range_ = re.findall(r'¥([^$]*)¥(€[^$]*€)?', code.text)[0] # 分离表达式与范围(如果有)
- x_r = (-10, 10)
- y_r = (-20, 20)
- if range_ != '': # 定义了范围
- ranges = range_[1:-1].split('|')
- if len(ranges) in (1, 2): # 定义的范围正确
- x_r = tuple(int(i) for i in ranges[0].split(','))
- if len(ranges) == 2: # 定义了y范围
- y_r = tuple(int(i) for i in ranges[1].split(','))
- code.tag = 'img'
- code.set('src', f"""data:image/png;base64,{(function_drawing(
- function=lambda x: eval(expression.split('=')[1]), x_range=x_r, y_range=y_r
- ))}""") # 绘制函数图像
- code.set('alt', 'Base64 函数图片')
- else: # 不支持扩展语法
- code.tag = 'span'
- code.set('class', 'block')
- code.text = '该平台不支持扩展语法'
- elif re.match(r'\{[^$]*}', code.text): # 是强调
- code.tag = 'span'
- code.set('class', 'block')
- key = code.text[1:-1] # 去掉两边的{}
- if key in self.variable:
- code.text = self.variable[key]
- else:
- code.text = key
+ elem.remove(code)"""
+ elif re.match(r'¥[^$]*¥', code.text): # 是数学函数(单行)
+ if EXTRA_ABLE: # 支持扩展语法
+ expression, range_ = re.findall(r'¥([^$]*)¥(€[^$]*€)?', code.text)[0] # 分离表达式与范围(如果有)
+ x_r = (-10, 10)
+ y_r = (-20, 20)
+ if range_ != '': # 定义了范围
+ ranges = range_[1:-1].split('|')
+ if len(ranges) in (1, 2): # 定义的范围正确
+ x_r = tuple(int(i) for i in ranges[0].split(','))
+ if len(ranges) == 2: # 定义了y范围
+ y_r = tuple(int(i) for i in ranges[1].split(','))
+ code.tag = 'img'
+ code.set('src', f"""data:image/png;base64,{(function_drawing(
+ function=lambda x: eval(expression.split('=')[1]), x_range=x_r, y_range=y_r
+ ))}""") # 绘制函数图像
+ code.set('alt', 'Base64 函数图片')
+ else: # 不支持扩展语法
+ code.tag = 'span'
+ code.set('class', 'block')
+ code.text = '该平台不支持扩展语法'
+ elif re.match(r'\{[^$]*}', code.text): # 是强调
+ code.tag = 'span'
+ code.set('class', 'block')
+ key = code.text[1:-1] # 去掉两边的{}
+ if key in self.variable:
+ code.text = self.variable[key]
+ else:
+ code.text = key
class CodeBlock(Treeprocessor):
diff --git a/README.html b/README.html
index d72c340..a977b09 100644
--- a/README.html
+++ b/README.html
@@ -102,6 +102,7 @@
9 列表
10 表格
@@ -169,9 +170,9 @@
4 代码块
4.1 单行
4.1.1 LaTex
- 这是\(CO_2\)二氧化碳
- 这是\(H_2O\)水
- \(\lg\left(\frac{目标生物的理智值}{稳定折磨型工具人的理智值}\right)\)
+ 这是
\(CO_2\)
二氧化碳
+ 这是
\(H_2O\)
水
+ \(\lg\left(\frac{目标生物的理智值}{稳定折磨型工具人的理智值}\right)\)
4.1.2 函数
// 不定义范围
// 定义了x范围
@@ -257,7 +258,7 @@
- 引文内添加klzzwxh:0038klzzwxh:0039下划线删除线高亮
+ 引文内添加klzzwxh:0039klzzwxh:0040下划线删除线高亮
7 提纲
7.1 提纲号
@@ -295,6 +296,38 @@
C
D
+ 9.3 释义列表
+
+ - A
+ -
+
+ - a
+ - b
+ - c
+
+
+ - B
+ -
+
+
+ - 强调值
+ -
+
+
+ - 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 表格
diff --git a/README.md b/README.md
index f249b0e..b4a72ba 100644
--- a/README.md
+++ b/README.md
@@ -252,6 +252,30 @@ cd ../..
- C
- 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 表格
| 表头1 | 表头2 | 表头3 |