What's a good way to go up one header / section?

# Title
## h2 1
Content under h2 1 under root

## h2 2
Content under h2 2 under root

### h3 1
Content under h3 1 under h2 2 under root

***

a) Content under h3 1 under h2 2 under root (hdiv used as thinking space)
OR
b) Content under h2 2 under root (hdiv used as up one level)
OR
c) Content under root

I have an use for a) and b) almost everywhere. How can I define ‘up one level’, while still retaining hdiv, or something else, as a seperator inside an element (h3)?

I have a technical answer and a practical answer. I’ll start with the latter.

(I’m probably giving you more than you asked for, but I wanted to write this up for reasons explained at the very bottom)

The Practical

While (b) and (c) may make logical sense with respect to your content, unless you use indentation or another visual indicator of explicit, nested sections, it won’t make visual sense. Look at the “thinking space” in your question. How would the reader know that the content doesn’t belong to the section it appears immediately under, but rather to a parent section?

explicit, nested sections

To illustrate, here is your question reformatted with visually explicit, nested sections:

Title

h2 1

Content under h2 1 under root

h2 2

Content under h2 2 under root

h3 1

Content under h3 1 under h2 2 under root

a) Content under h3 1 under h2 2 under root (hdiv used as thinking space)

OR
b) Content under h2 2 under root (hdiv used as up one level)

OR
c) Content under root

Almost no one wants to visually structure their content this way. It adds a lot of visual noise that isn’t necessary and looks awful. The two common exceptions are:

  • programming code. Either using indentation or syntax (often both).
  • nested block quotes, which both Markdown and HTML support.

While code structure is very logical, most prose authors don’t want or need their content to look like code. It’s adding a lot of visual complexity simply so one can make an outer level conclusive remark at the end.

Block quotes are the exception for prose, for a couple of reasons. Prose needs to seamlessly return to the parent level after an embedded quotation. The visual impact of such a structure is minimal, as it affects only small portions of a document, and nesting almost never exceeds one level.

The Technical

Markdown

Markdown doesn’t support explicit sections. Headings only imply sections and nesting structure.

The best you can do is to repurpose block quotes, as I did above, as follows:

# Title

> ## h2 1
> Content under h2 1 under root

> ## h2 2
> Content under h2 2 under root
>
> > ### h3 1
> > Content under h3 1 under h2 2 under root
> >
> > a) Content under h3 1 under h2 2 under root (hdiv used as thinking space)
> 
> OR
> b) Content under h2 2 under root (hdiv used as up one level)

OR
c) Content under root

If you are rendering to HTML, you would have to either use CSS to likewise visually repurpose blockquote, or you would have to make/use a custom Markdown renderer to transform Markdown block quotes to HTML5 nested sections.

HTML5

HTML headings work the same way as Markdown’s. Different levels of headings as well as the content below each heading are all siblings at the same level of the DOM tree. Sections and nesting structure are implied only.

HTML5 does support explicit nested sections. In fact, there was an attempt ten years or so ago to push everyone to use them instead of “flat” headings. There was even an official algorithm to convert the structure implied by flat headings into explicitly nested sections and an expectation that browsers would apply it to the DOM. Here is an online implementation. This push has since been abandoned. Because the browser vendors did not want to implement it. See also The Document Outline Dilemma, Computer says NO to HTML5 document outline and A decade + a year of heading backwards.

If you decide to use nested HTML5 sections, you would still have to use CSS to come up with a rendering that makes it visually explicit, as in my example above.

plain text formats that support nested sections

Though I believe only DocBook supports popping out to a parent section as you want to do, and it is able to do that because it is an XML-based format.

Conclusion

For aesthetic and practical reasons, most authors don’t want to present their prose as shown in The Practical above. Instead, they will employ the solution I am using in this very section you are reading now: Simply start a new section with the right title.

That Markdown and other formats don’t support what you want to do reflects this practical reality. That is my opinion at least.


:triangular_flag_on_post: p.s.

The reason I spend so much time answering forum posts such as this is because I have to wrestle with and pin down these sorts of questions for a side project of mine: Plain Text Style Sheets. It aims to, amongst other things, provide a solution for many of the countless asks on this forum. I hope to make an announcement here soonish, but it is a side project so progress is slow. :grimacing:

I’ve suggested before to (optionally) treat the three different kinds of “thematic breaks” as various kinds of section breaks: