sectionNumbering.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/python3
  2. import os
  3. import operator
  4. import sys
  5. files = {}
  6. for x in os.listdir(sys.argv[1]):
  7. if x.endswith(".doxy"):
  8. with open(sys.argv[1]+x, "r", encoding="utf-8") as fin:
  9. for line in fin.readlines():
  10. if "\page" in line:
  11. line = line.replace("/*! \page ", "").strip()
  12. files[x] = line[0:line.index(" ")]+".html"
  13. sfiles= dict(sorted(files.items(), key=operator.itemgetter(0)))
  14. htmlfiles = ["index.html"]
  15. htmlfiles.extend(sfiles.values())
  16. htmldir=sys.argv[2]+"/"
  17. chapter=0
  18. for x in htmlfiles:
  19. chapter+=1
  20. section=0
  21. with open(htmldir+x, "r", encoding="utf-8") as fin:
  22. with open(htmldir+x+".count.html", "w", encoding="utf-8") as fout:
  23. for line in fin.readlines():
  24. if "<div class=\"title\">" in line:
  25. line = line.replace("<div class=\"title\">", "<div class=\"title\">"+str(chapter)+". ")
  26. if "<h1>" in line:
  27. section += 1
  28. line = line.replace("<h1>", "<h1>" + str(chapter) + "." + str(section))
  29. subsection = 0
  30. if "<h2>" in line:
  31. subsection += 1
  32. line = line.replace("<h2>", "<h2>" + str(chapter) + "." + str(section) + "." + str(subsection))
  33. subsubsection = 0
  34. if "<h3>" in line:
  35. subsubsection += 1
  36. line = line.replace("<h3>", "<h3>" + str(chapter) + "." + str(section) + "." + str(subsection) + "." + str(subsubsection))
  37. fout.write(line)
  38. os.rename(htmldir+x+".count.html", htmldir+x)