My opinions:
* write in Pandoc Markdown.
* give each sentence its own line. It helps with composing and reordering, and gives much cleaner diffs if you keep this in a git repo.
* personally, I used GitHub for html, Pandoc to make the epub, then Calibre to turn the epub into a pdf.
The "internal links" thing is a pain, admittedly. I have an idea for a workaround:
* sprinkle hidden, unique <a id="ch1.2"></a> around
* on GitHub, use links like chapter1#ch1.2
* for Pandoc, preprocess to remove the filename before the #
I'm working with a big enough book that it's an undertaking, so I haven't done this yet.