forked from CrossDark/CrossDown
0.9.1添加数学函数
This commit is contained in:
parent
6de7e32ca3
commit
b31bb0acaa
17
CrossDown.py
17
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'<p>\(\1\)</p>', code)
|
||||
elif re.match(r'¥[^$]*¥', code): # 是数学函数(单行)
|
||||
self.codes[index] = re.sub(fr'¥([^$]*)¥', r'<p>\(\1\)</p>', 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] = '<mark>该平台不支持扩展语法</mark>'
|
||||
else: # 是突出块
|
||||
self.codes[index] = f'<span class="block">{code}</span>'
|
||||
|
||||
|
@ -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()
|
||||
|
File diff suppressed because one or more lines are too long
@ -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
|
||||
`
|
||||
|
Loading…
Reference in New Issue
Block a user