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