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})$`
'''


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM