现在知乎已经支持Markdown文件导入了,有点遗憾的是tex公式还不支持,需要自己打,但这个可以通过正则替换解决,写了个python脚本用于替换,github地址。import sys
import re
interline_tag = ‘\n<img src=”https://www.zhihu.com/equation?tex={}” alt=”{}\\\\” class=”ee_img tr_noresize” eeimg=”1″>\n’
interline_pattern = “\$\$\n*(.*?)\n*\$\$”
inline_tag = ‘<img src=”https://www.zhihu.com/equation?tex={}” alt=”{}” class=”ee_img tr_noresize” eeimg=”1″>’
inline_pattern = “\$\n*(.*?)\n*\$”
def replace_tex(content):
def dashrepl(matchobj, tag):
formular = matchobj.group(1)
return tag.format(formular, formular)
content = re.sub(interline_pattern, lambda mo: dashrepl(mo, interline_tag), content)
content = re.sub(inline_pattern, lambda mo: dashrepl(mo, inline_tag), content)
return content
if __name__==’__main__’:
assert len(sys.argv) > 1, “Error: need filename as a argument”
filename = sys.argv[1]
with open(filename, ‘r’) as f:
content = f.read()
with open(filename, ‘w’) as f:
f.write(replace_tex(content))所以只需要先用py处理下md文件,替换掉行内和行间公式:把py文件放在md文件统计目录下,将md文件名作为参数运行python即python3 replace_tex.py your_markdown_file.md 直接在知乎文章编辑见面导入md文件<img src=”https://pic2.zhimg.com/50/v2-edad4976de88a1c168ea9c5257b8089d_hd.jpg?source=1940ef5c” data-caption=”” data-size=”normal” data-rawwidth=”1994″ data-rawheight=”1466″ data-default-watermark-src=”https://pic4.zhimg.com/50/v2-2bb8edd211cb680165b0b513b841f14d_hd.jpg?source=1940ef5c” class=”origin_image zh-lightbox-thumb” width=”1994″ data-original=”https://pic4.zhimg.com/v2-edad4976de88a1c168ea9c5257b8089d_r.jpg?source=1940ef5c”/>