markup.py 774 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env python3
  2. import os
  3. import re
  4. #markup file
  5. def mdtohtml(str):
  6. #some cosmetics
  7. str = str.replace("(c)","©")
  8. str = str.replace("(r)","®")
  9. str = str.replace("(tm)","™")
  10. #replace "<" and ">" with entities
  11. str = str.replace("<","&lt;")
  12. str = str.replace(">","&gt;")
  13. str = str.replace("\n&gt;","\n>")
  14. #convert markdown to html using the "Markdown" python module
  15. #not working? install python and pip, then the markdown module
  16. #for Debian, Ubuntu, Linux Mint and Debian-based distros: "sudo apt install python3-pip"
  17. #then: "pip3 install markdown"
  18. open("tmp.md","a").write(str)
  19. os.system("python3 -m markdown tmp.md > tmp.html")
  20. os.system("rm -f tmp.md")
  21. str_html = open("tmp.html").read()
  22. os.system("rm -f tmp.html")
  23. return str_html