Using Scrivener to split markdown files


My goal is to generate separate markdown files from a Scrivener project on compile. Scrivener currently saves a single, monolithic .md file from the selected documents at compile. I would like that it could save separate .md documents, split at a certain hierarchic level in the Binder.

This is because I would like to use Quarto to create a website from a complex Scrivener project. Quarto can’t split a single .md file into separate .md files corresponding to separate .html pages after processing.

While waiting for a solution right in the Compile dialog, I wonder if this workaround could work:

  1. Generate an .md file from Scrivener > Compile > MultiMarkdown.

  2. Import and Split the generated .md file. If no conversion to RTF is chosen, these should be pure markdown files.

  3. Export the separate Scrivener documents as individual .md files. This should preserve the “pure” nature of the .md files.

  4. Move the separate .md files into Quarto’s project folder.

  5. Render it to HTML, PDF, or whatever you want.

Could this work?


In the meantime, I’ve found a script that seems to allow what I need. It took me a bit to go through the various python and pip installations, but there are generous developers helping to make things clear.



The main issues with splitting a document are reference links, footnotes, referenced-linked figures or in-text cross-document links. These must all be corrected before/at splitting, if not then you will end up with broken links, figures and footnotes across your project. I doubt Scrivener handles this on import, and this is not mentioned as a feature in the tool you have found. You should check it does this, unless of course you don’t have links from one chapter to another, use figures, reference links or footnotes (Scrivener does generate reference links BTW…)

1 Like

This is something I hadn’t considered. I have tons of cross-references/links, and they will likely increase when switching from a first-PDF to a first-HTML project.

I must check, but it really looks like the monolithic .md file compiled by Scrivener doesn’t include anchors to .html files, that still don’t exist when compiling. It is to be seen if the mdsplit tool can do it, despite not being documented.

Apparently, at the moment it looks like what I want to achieve can only be done by directly writing in a code editor like Visual Studio or RStudio. But then, these are tools for software engineers, where the code is always ready to jump up, and the tools for writers are reduced to a bare minimum. In other words, they smell of code…


There isn’t too much technical work to make a splitter and it may be mdsplit does handle all of this already (I didn’t use it). Bernardo definitely has some code somewhere that handles all reference links to inline links, and the splitting to separate files is trivial. That only leaves the internal cross-document links that need to be converted to file#section inline links. Pandoc’s Lua API now has a chunking engine: Pandoc - Pandoc Lua Filters and I suspect a Lua filter would be the most elegant tool for this, but there are probably many ways to solve this, just needs someone with time and skill to make it so!

EDIT: you should open an issue for Quarto as this option makes sense for their tool, giving a user more flexibility to switch from document to web/book mode…

1 Like