Shoutout to some excellent software for ebook wrangling.
The first is the "Standard Ebooks"[1] toolset, which is a suite of Python scripts to create, process, and build ebooks in all common formats. The results on the Standard Ebooks site speak for themselves. They're impeccable in every way, and far better than many big name, commercially produced efforts.
GitHub: https://github.com/standardebooks/tools
How to use: https://standardebooks.org/contribute/producing-an-ebook-ste...
The second is Sigil, which is a great editor if you prefer to work with a GUI:
GitHub: https://github.com/Sigil-Ebook/Sigil
Homepage: https://sigil-ebook.com/about/