Python实现 Typora数学公式 转 有道云笔记Markdown数学公式

话不多说上代码,可以按照自己的需求把匿名函数改成普通函数,改不来的可以加我微信我帮你改。

块状数学公式转换

import re

test_str = r'''
$D={\{\vec{x_1},\vec{x_2},\cdots,\vec{x_m}\}}$
$\vec{x_i}=(x_{i1};x_{i2};\cdots;x_{id})$
'''

change_str = re.sub('\$(.*?)\$', lambda m: '```math\n{}\n```'.format(m.group(1)), test_str.strip())
print(change_str)

'''
\`\`\`math
D={\{\vec{x_1},\vec{x_2},\cdots,\vec{x_m}\}}
\`\`\`
\`\`\`math
\vec{x_i}=(x_{i1};x_{i2};\cdots;x_{id})
\`\`\`
'''

直接上图

行内数学公式转换

import re

test_str = r'''
行内数学公式:$D={\{\vec{x_1},\vec{x_2},\cdots,\vec{x_m}\}}$<br>
行内数学公式:$\vec{x_i}=(x_{i1};x_{i2};\cdots;x_{id})$
'''

change_str = re.sub('\$(.*?)\$', lambda m: '`{}`'.format(m.group(0)), test_str.strip())
print(change_str)

'''
行内数学公式:`$D={\{\vec{x_1},\vec{x_2},\cdots,\vec{x_m}\}}$`<br>
行内数学公式:`$\vec{x_i}=(x_{i1};x_{i2};\cdots;x_{id})$`
'''

猜你喜欢

转载自www.cnblogs.com/nickchen121/p/10271301.html