diff --git a/CrossDown.py b/CrossDown.py index 6dde088..9944fe2 100644 --- a/CrossDown.py +++ b/CrossDown.py @@ -4,7 +4,7 @@ import re import markdown try: # 检测当前平台是否支持扩展语法 - import Extra + import CrossMore EXTRA_ABLE = True except ModuleNotFoundError: EXTRA_ABLE = False @@ -239,7 +239,20 @@ class CodeBlock: elif re.match(r'\$[^$]*\$', code): # 是LaTex代码(单行) self.codes[index] = re.sub(fr'\$([^$]*)\$', r'
\(\1\)
', code) elif re.match(r'¥[^$]*¥', code): # 是数学函数(单行) - self.codes[index] = re.sub(fr'¥([^$]*)¥', r'\(\1\)
', code) + if EXTRA_ABLE: + expression, range_ = re.findall(r'¥([^$]*)¥(€[^$]*€)?', code)[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(',')) + self.codes[index] = CrossMore.function_drawing(function=lambda x: eval(expression.split('=')[1]), x_range=x_r, y_range=y_r) + + else: + self.codes[index] = '该平台不支持扩展语法' else: # 是突出块 self.codes[index] = f'{code}' diff --git a/Extra.py b/CrossMore.py similarity index 90% rename from Extra.py rename to CrossMore.py index 3af1a35..7505146 100644 --- a/Extra.py +++ b/CrossMore.py @@ -4,7 +4,7 @@ import base64 from io import BytesIO -def plot_function_to_base64(function, x_range=(-10, 10), y_range=(-20, 20), dpi=100): +def function_drawing(function, x_range=(-10, 10), y_range=(-20, 20), dpi=100): # 创建一个图像和坐标轴对象 fig, ax = plt.subplots() diff --git a/README.html b/README.html index 42904dd..91a8835 100644 --- a/README.html +++ b/README.html @@ -68,6 +68,10 @@\(CO_2\)
\(H_2O\)
+
+
+
@@ -123,6 +127,7 @@
点不能出现在开头或结尾,例如
.6.1.2 错误示范
6.1.3. 错误示范
+
7 注释
7.1 强注释
7.2 弱注释
diff --git a/README.md b/README.md
index 2d8554b..4e39604 100644
--- a/README.md
+++ b/README.md
@@ -45,6 +45,10 @@ ___
3.1.1 LaTex
`$CO_2$`
`$H_2O$`
+3.1.2 函数
+`¥y=x*2+1¥` // 不定义范围
+`¥y=x**2¥€-50,50€` // 定义了x范围
+`¥y=x**3¥€-50,50|-100,100€` // 定义了y范围
3.2 多行
3.2.1 YAML
`
diff --git a/setup.py b/setup.py
index c591c84..5113d66 100644
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,10 @@ setuptools.setup(
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/CrossDark/CrossDown",
- packages=setuptools.find_packages(),
+ py_modules=[
+ 'CrossDown',
+ 'CrossMore',
+ ],
install_requires=[
'markdown',
],