This is exactly what pandoc’s --section-div flag does. Remember that CommonMark specifies primarily an AST and that the HTML examples are only one valid serialization of that AST.
Attempting to place attributes to sections to allow for easier slideshow coding. Metadata in documents
Harder than it seems (anything not recognized as valid html attribute is displayed as a div):
----
:id: slide1
:class: slidestyle
note: this is a test slide
# slide title
normal text here
---
renders as
<hr>
<section id="slide1" style="slidestyle" >
<div class="metadata note" > this is a test slide </div>
<h1> slide title </h1>
<p> normal text here </p>
</section>
<hr>
edit: To into consideration that people may display addresses on the “metadata field”, so better give people the option of displaying it or not.
AFAIU, the current spec treats this snippet as a flat AST such as:
h1: Foo
h2: Bar
paragraph: p
If it was treated as this instead:
h1: Foo
section
h1: Bar
paragraph: p
it would make the hierachiecal interpretation standard instead of relying on the implementation to rebuild the structure from the flat view.
Well, in Markdown these two documents are different:
# Foo
### Bar
p
# Foo
## Bar
p
On your proposal, as I understand it, they’d be parsed into the same AST, so there’d be no way to go back; information would be lost. The problem is that there are multiple flat structures corresponding to a single hierarchical structure.
Markdown was created in the XHTML era, whereas <section> is from HTML5, so it wouldn’t have been a consideration.
The use of sections is considered good practice. It’s worth taking a step back and asking if they need to be explicit in Markdown. A rule could be added to the parser to add opening and closing HTML section tags based on the header level. This would cover a lot of cases and save the writer from having to explicitly add them. We’re then left asking how to implement sections for only the sections that do not follow a pattern based on heading level.
Well if we consider section+header > header in the hirachy of importance then could we do this via flowerbox headers? e.g. with mb21 example, we would instead type
======================
Foo
======================
---------------
Bar
---------------
p
There may be no need for any kind of explicit section syntax. Instead, just get the parser to add the sections based on a parser flag and the locations of the headings. This would be an extension to the default rendering mode (no sections). Adding the sections based on implicit considerations keeps the document significantly lighter; this feels more inline with the rest of Markdown.
There maybe be no need for any kind of explicit section syntac but if people want to reliably markup sections using the existing syntax, there probably needs to be an interoperable way to infer section from the existing markup (i.e. write the algorihm in some spec). And it might be useful to be able to add classes (and other attributes) to the sections. Another possible need which is not covered at all is how to end a section.