鱼C论坛

 找回密码
 立即注册
查看: 887|回复: 1

md转换html问题

[复制链接]
发表于 2019-5-22 23:56:28 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 河蟹 于 2019-5-23 00:01 编辑

https://github.com/benmahr/RenZhengfei
从这个下载的文件

代码如下:

  1. import markdown
  2. import os
  3. import codecs


  4. head = """<!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  8. <style type="text/css">
  9. code {
  10.   color: inherit;
  11.   background-color: rgba(0, 0, 0, 0.05);
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. """

  17. foot = """
  18. </body>
  19. </html>
  20. """
  21. filepath = "G:\github_renzhengfei_26208\RenZhengfei"
  22. savepath = "G:\github_renzhengfei_26208\RenZhengfei\ALL-html"
  23. if not os.path.isdir(savepath):
  24.     os.mkdir(savepath)
  25. os.chdir(savepath)

  26. i = 0
  27. pathDir = os.listdir(filepath)
  28. for allDir in pathDir:
  29.     if (allDir == "pdf"):
  30.         continue
  31.     name = allDir
  32.     print(name)

  33.     os.chdir(filepath)
  34.     fp1 = codecs.open(name, mode="r", encoding="utf-8")
  35.     text = fp1.read()
  36.     html = markdown.markdown(text)
  37.     fp1.close()
  38.    

  39.     fname = name.replace('md', 'html')

  40.    
  41.     os.chdir(savepath)
  42.     fp2 = codecs.open(fname, mode="w", encoding="utf-8", errors="xmlcharrefreplace")
  43.     fp2.write(head + html + foot)
  44.     fp2.close()

  45. print(i)
复制代码


错误信息:
微信图片_20190522235424.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-5-23 09:11:52 | 显示全部楼层
你权限不够
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-1-15 23:53

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表