Surrounding hashes on MultiMarkdown Export

Hello,

I export to MultiMarkdown with the Folder Names as chapter titles. Scrivener surrounds the title with hashes

Title

Leanpub only wants starting hashes like

Title

How do I tell Scrivener to not add trailing hashes?

I currently export as TXT with prefixes of # and ## for Chapters, but the solution is not the best.

Thanks
Stephan

Dear developers and community,

Thanks for making Scrivener awesome.

I’m using Scrivener on Word to compile to R markdown. Currently, all headers are exported with opening and closing hashes, like so: # Title #, and ## Subtitle ##.

However, I’d like to only add level-sensitive openings, so I can add other markdown options. E.g. # Title {-}. I noticed that such functionality existed on Mac (Scrivdown | R-bloggers), with the option to untick ‘Add closing hashes to titles’.

However, is there a way to do this in Windows?

Many thanks,
Jessie

Yes, this option unfortunately still does not exist, nor does it work internally if you try to force it by adding the correct XML to your compile settings file directly (in fact all of the supplied Pandoc-based formats already do, to no avail).

Without external tools

The Scrivener-only solution at this point in time requires a bit more work, more like how a rich text user would have to use Scrivener with multi-level headings:

  • Having a type-based declaration of the project structure in Project Settings.
  • Assign those types to level-specific Layouts in the compiler.
  • Setting up these layouts to generate title prefix, which outputs the correct number of hashes.

While it involves more manual setup than a Markdown user would typically have to employ, it is all fairly automatic once you do have it set up.

The attached sample project demonstrates a simple 3-level setup, which should be enough to show how one could add more hierarchy if needed.

closing_hashes_demo.zip (160.3 KB)

Project setup notes...
  1. Open Project ▸ Project Settings... to the Section Layouts pane.
    • We have some basic generic hierarchical names here. This is where you would add more.

    • In the Default Types by Structure tab, you can see how these generic names are applied to the outline structure automatically.

      Note: the Export... button would export both the name list and the structure settings to a file that can be imported into your project, if this is a good enough start for you.

    • While here, click on the Custom Metadata tab. I’ve created an Attributes field to demonstrate how we can keep this kind of clutter out of the binder itself.

  2. So to see these two settings in action, cancel out of project settings and take a look at the Outliner view of the Draft.
    • Here we have the Attributes column added, and this where you could type in custom IDs, classes, or whatever else you need.
    • The third column shows the Section Types, so you can see how the automatic structure feature is working. Changing indents or dragging things around will cause them to automatically become “chapters”, “subsections” or whatever.
  3. Now head into the compiler. From the preview column in the middle, you can see how the headed sections all have a similar setup, only the number of hashes are different. Double-click on the “Pandoc Hierarchical Levels” format, in the left sidebar, to take a look at the setup.
    • In Section Layouts, click on the Title Options tab, and cycle through the three “Level n” layouts. Pretty straight-forward stuff here in the prefix field.
    • The setting that might be easy to miss though is at the bottom of this tab. Normally the Number of hashes dropdown is set to “by level”, but here we use “0” to take total control of heading output.
    • In the suffix field we have the Attributes field being inserted, if there is text to insert, after the output of the binder item title.

That’s all there is too it. If you want to use this compile Format as a starter, either change the Save to dropdown at the top to “My Formats” (to make it global), or cancel out, then use the gear button in the Format sidebar to “Export Format…”.

Sometimes techniques like this can be really useful. Maybe you want to force a particular part of the output to use a specific heading level instead of whatever the outliner dictates it would be (either fully automatically, or with a configuration such as the one demonstrated here). Manually assigned section types, or local type structure overrides, can achieve this. I do something similar for the “What’s New” appendix in the user manual, where I don’t want the typical multi-level numbered heading setup.

But in this case, we can also use it to work around missing implementations. The convenience of multi-level automatic heading output is just that… a convenience.

External processing

There is one other approach, though it is one I am less familiar with on Windows, and that is post-processing automation. On Linux for example, I could run Scrivener’s raw output through sed and strip out the extraneous hashes on the fly, or perhaps run it through a Ruby script that does that and more. Like I say, I don’t really know much about Windows, or whether it has something equivalent to sed preinstalled, or if that’s something you’d have to install, etc. But if you do have scripting knowledge, and maybe even a scripting environment already installed, then you can do anything to Scrivener’s .md file that you’d be able to do otherwise, only have it executed automatically upon clicking the Compile button.

2 Likes

Dear Amber,

Thank you for this! Option 1 seems like a great work around which I will try.

All the best,
Jessie

There are other things you could do with Attributes as well. I was thinking, if you only ever use the {-} unnumbered suffix, then that’s really more of an alternate Section Layout (one called “Unnumbered Heading” for instance) that you pick manually from the Inspector or in the Outliner, than something that requires a most customisable front-end and manually typing it in every time.