Skip to content

Instantly share code, notes, and snippets.

@lele-blue
Last active October 1, 2021 06:32
Show Gist options
  • Select an option

  • Save lele-blue/7a494bcea31373cd09a2097d785544fc to your computer and use it in GitHub Desktop.

Select an option

Save lele-blue/7a494bcea31373cd09a2097d785544fc to your computer and use it in GitHub Desktop.
import re
import os
summary = open("book/SUMMARY.md", "r").read().splitlines()
order = ["SUMMARY.md"]
for summary_line in summary:
pattern = re.compile(r" *[\*\-] ?\[(.+)\] ?\((.+)\)")
if re.match(pattern, summary_line):
order.append(re.findall(pattern, summary_line)[0][1])
out = open("out.md", "w")
for chapter in order:
out.write(open(os.path.join("book", chapter), "r").read() + "\n")
@lele-blue
Copy link
Author

pandoc -o book.epub meta.yml out.md --toc --toc-depth=2 --css=css.css

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment