For “reasons” I was looking for a way to convert an existing markdown-course to a “moodle book” resource. (I know, I know, not really the way to go, but still…). I found this interesting python-script that exactly does this, however, it’s not very up-to-date. My Python-skills aren’t very on par, but I did manage to make it work on Python 3.7 and you can find my updated script here.
The script works nice and well and even creates nice “code fragments” and is able to import your images:

The main drawback currently is that the needs a very strict folder structure and filenames (all files and folders have to be numbered and need to contain a topic.md file per folder).
Things you need to consider:
- Markdown blockquotes are converted to a rather large font (which you can change of course)
- Each chapter needs it own \book folder where the actual content will be (which will mean to you might need to rearrange your existing markdown folder structure)
- Use the -pagetitles option if you can’t import the newly created book archive because your page titles are too long: the script will use the first header as title in your markdown, but for reasons (yet) unbeknownst to me it also used the text following the header resulting in an HTML <title> that was too long for Moodle to work with.
- Images need to be in a subfolder of each \book folder. Meaning you can’t use one big assets folder for all your chapters (something gitbook prefers)