Obsidian to Leanpub

I want to export my vault as a single markdown file. This needs to be recursive and to drag in every linked file from every sub-directory

Suggestions? I would love to find (a) a solution or (b) some existing open source plugin that I can steal from. I don’t mind writing code.

Background: I would like to use Obsidian to write a leanpub book. The biggest obstacle seems to be the fact that I fragment my writing into many small, hierarchical pieces when using Obsidian and I don’t (yet) know how drag all of that work over to leanpub. It appears that “export to PDF” does mostly what I want, except that it produces PDF instead of markdown. Changing format of links to leanpub format seems to be easy (a REGEX script). Traversing the hierarchy of notes looks like work that might already exist but I don’t know what search phrase(s) to use (hence, I ask before doing it myself).

If you’re on Mac or Linux you could use a shell script with cat and some kind of recursive loop.