An EPUB is a zip of web pages with a table of contents, and a Markdown file is most of the way there already.
A reader builds its contents and its next-chapter button from separate files, not from headings, so one long page is a book with no chapters however well it is headed. A book also wants its pictures inside it — most readers will not fetch one from the web — a manifest naming every file, and a title and a language, which the reader uses to hyphenate and to read aloud.
From the headings that repeat. Two or more top-level `#` headings make a chapter each; one `#` title over several `##` sections makes a chapter per section, with the title opening the first. A document with neither is one chapter, which is what it was.
Apple Books, Google Play Books, Kobo, Calibre and Thorium open an EPUB directly, and Send to Kindle has taken them since 2022. To check a book before it goes anywhere, open it in Calibre or run it through EPUBCheck, the validator the stores use themselves.
The contents first: every chapter should carry the name of its heading. Then any page with a formula or a diagram — they travel as MathML and SVG, which every current reader draws and some older e-ink models do not.