Exporting to markdown with the correct heading levels

Hi,

I can’t have a Scrivener project compiled to multimarkdown, with the headings in the source file converted to markdown headings.

What I do is this:

  1. Disable Titles from the section type, so that the document names in the Binder are not exported. I have to prevent them to be exported, because they will remain in English even in translated projects, to help easily identify the various sections.

  2. Apply HTML levels to heading paragraphs in the text, so that they make a structure. Save the current status into a paragraph style. Top-level headings with be H1, then H2, and so on.

  3. Be sure the same paragraphs of the editor exist in the compile format.

After compiling to markdown, the headings are converted to ordinary paragraphs. Why is this happening?

(If Scrivener can’t export heading levels from styles, I’m thinking to a workaround, where I add the hashtags to the compile style’s prefix. And this actually works).

Paolo

Hi Paolo, so if I understand you want to put your headings as text in the documents themselves? Then you need to use Styles; apply Heading 1 to 6 to your headings. Next you make sure that your compile format has the same styles and apply the prefix, e.g. for Heading 2:

This will then transform the styles into markdown syntax. The same basic principle applies to all uses of styles.

You could also use Section Layouts with metadata and placeholders as a more fancy way to do this. Scrivener usually has several roads when going to Rome :blush:

1 Like

I’m discovering it more and more!

I am using the hashtags added as prefix to paragraph styles, but I’ll keep as an alternative the solution of adding them to a section layout.

I also discovered the power of this system: I have to create a six-level structure for the PDF, but only a three-level structure for the web pages (while the manually entered index in Quarto will preserve the full structure).

Nothing could be easier: a compile format will give me the right levels for the PDF, and another one the right levels for the web pages. The same project, two completely different outputs.

Paolo

1 Like

Since it sounds like you have a good approach already set up, this is more just for anyone else coming across this thread, that would like a system less driven by styled text in the editor.

Another approach that would give you a dynamic heading level based on the outline is to create a custom metadata field, something like “PublicTitle”, and then add that to your title prefix field for the section layout, leaving the Title checkbox off. That way you can leave the Number of hashes setting at the bottom of the Title Options tab to “By Level”.

And of course if one has gone through the trouble of setting up depth-aware Section Types in the project, with the intention of having specific layouts per type, you can also force how many hashes to use for that layout. It may still technically be level-based given one’s Section Type settings, but the “engine” driving it is different—and it can be useful in cases where you need to force the top level to be something other than h1.

That isn’t ordinarily something you would have to bother with in the Markdown side of Scrivener, that proliferation of types and layouts just to handle depth, but in cases where one intends to swap between the rich text side and Markdown, it’s a viable approach.

2 Likes

Yup, Scrivenerian magic rocks! :star_struck:

1 Like