python编译markdown时,html内容会重复增加
代码如下
md.py:
def main(argv): md_name = argv[0]
with open(md_name, mode='r', encoding='gbk') as mdfile:
# with codecs.open("friendly.css", mode='r', encoding='utf-8') as cssfile:
md_text = mdfile.read()
# css_text = cssfile.read()
extras = ['code-friendly', 'fenced-code-blocks', 'footnotes']
html_text = markdown.markdown(md_text, extras=extras)
print(html_text)
html_name = '%s.html' % (md_name[:-3])
with open(html_name, 'w', encoding='utf-8', errors='xmlcharrefreplace') as output_file:
output_file.write(html_text)
if __name__ == "__main__":
if len(sys.argv) == 2:
main(sys.argv[1:])
else:
print("Error:please specify markdown file path")
md.md
####因子分析<p><iframe style="width: 100%; height: 500px;" src="../report/dataBaseStatus.html" frameborder="0"></iframe></p>
编译 python mk.py mk.md >> mk.html
第一次编译时
第二次编译时
内容不会重新覆盖
请问应该怎么解决呢
回答:
你已经用python写文件了
... html_name = '%s.html' % (md_name[:-3])
with open(html_name, 'w', encoding='utf-8', errors='xmlcharrefreplace') as output_file:
output_file.write(html_text)
就不需要再用shell转向了:
python mk.py mk.md >> mk.html
二者保留一个就好。
以上是 python编译markdown时,html内容会重复增加 的全部内容, 来源链接: utcz.com/p/937650.html