Automatically decrement header levels with multi-document linking?

david.veldhouse's Avatar


10 Jan, 2018 01:49 PM

Hello all,

New to the forum, and I didn't find this in any discussions:

Is there a way to force Marked 2 to reduce header levels for multi-document files brought into a master index file?

I write a lot of technical content, and sometimes I mix-and-match different sub-sections that have multiple uses.

For example:

Header topic 1

Sub-header topic 1

...might be useful as a sub-section for a different topic, such as:

New Topic

<<[] this example I'd like to bring into with it's whole header hierarchy reduced by 1, so it's effective a sub-header of New Topic.


  1. Support Staff 1 Posted by Brett on 10 Jan, 2018 02:24 PM

    Brett's Avatar

    This can't be done using Marked's custom include syntax, but it can be accomplished using the mmd_merge syntax that Marked supports. Create an index file that contains nothing but filenames/paths and put #merge in the first line. You can then use indentation to manually adjust header levels:


    So if part1, 2 and have first level headers, it would now show up in the compiled document with a second-level header, and any subsequent headers within the file are decremented appropriately.

  2. 2 Posted by david.veldhouse on 10 Jan, 2018 04:10 PM

    david.veldhouse's Avatar

    That's great, and very useful! One problem is that I'm using Discount processing primarily due to its image scaling capabilities. I don't suppose you know if Discount supports #merge?

    Thanks again for the FAST response...

  3. Support Staff 3 Posted by Brett on 10 Jan, 2018 04:52 PM

    Brett's Avatar

    The merge is built into marked, it just compiles the document before passing it to whatever processor you're using.

    - Brett

  4. 4 Posted by david.veldhouse on 11 Jan, 2018 02:16 AM

    david.veldhouse's Avatar

    I see. That seems to work as advertised, thanks.

    Of course, I want my cake and eat it too:

    I can't build a dynamic table of contents this way like I can with Mark's slick "include" syntax, can I?

  5. 5 Posted by david.veldhouse on 11 Jan, 2018 02:21 AM

    david.veldhouse's Avatar

    Actually, I think I just answered my own question: putting the <!--TOC--> in the first document after the #merge command seems to work!

  6. Support Staff 6 Posted by Brett on 11 Jan, 2018 02:24 AM

    Brett's Avatar

    You can't stick a toc tag into the merge file, but you can create a toc.txt (or whatever) with a <!--toc--> tag in it and insert it where you want in the merged document.

    - Brett

  7. 7 Posted by david.veldhouse on 11 Jan, 2018 12:51 PM

    david.veldhouse's Avatar

    Yes, I ended up getting exactly the output I wanted. Thanks so much for the attention, Brett.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac