# Explicit section not possible?

**URL:** <https://talk.commonmark.org/t/explicit-section-not-possible/796>\
**Category:** Extensions\
**Created:** [October 9, 2014, 6:31am UTC](https://talk.commonmark.org/t/explicit-section-not-possible/796 "2014-10-09T06:31:01Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![diimdeep](https://talk.commonmark.org/user_avatar/talk.commonmark.org/diimdeep/32/137_2.png) [@diimdeep](https://talk.commonmark.org/u/diimdeep)\
**Post date:** [October 9, 2014, 6:31am UTC](https://talk.commonmark.org/t/explicit-section-not-possible/796/1 "2014-10-09T06:31:01Z")

</div>

From [HTML: The Living Standard](https://developers.whatwg.org/sections.html#headings-and-sections)

_For the following fragment:_

```html
<body>
 <h1>Foo</h1>
 <h2>Bar</h2>
 <blockquote>
  <h3>Bla</h3>
 </blockquote>
 <p>Baz</p>
 <h2>Quux</h2>
 <section>
  <h3>Thud</h3>
 </section>
 <p>Grunt</p>
</body>

```

_…the structure would be:_

1. Foo (heading of explicit body section, containing the “Grunt” paragraph)
2. Bar (heading starting implied section, containing a block quote and the “Baz” paragraph)
3. Quux (heading starting implied section with no content other than the heading itself)
4. Thud (heading of explicit section section)

_Notice how the section ends the earlier implicit section so that a later paragraph (“Grunt”) is back at the top level._

Is explicit section is not possible in pure markdown ?

---

<div class="post-metadata">

**Author:** ![vitaly](https://talk.commonmark.org/user_avatar/talk.commonmark.org/vitaly/32/396_2.png) [@vitaly](https://talk.commonmark.org/u/vitaly)\
**Post date:** [October 9, 2014, 1:11pm UTC](https://talk.commonmark.org/t/explicit-section-not-possible/796/2 "2014-10-09T13:11:51Z")

</div>

It’s possible via [html blocks](http://jonschlinkert.github.io/remarkable/demo/#md=%7B%22defaults%22%3A%7B%22html%22%3Atrue%2C%22xhtml%22%3Atrue%2C%22breaks%22%3Afalse%2C%22langPrefix%22%3A%22language-%22%2C%22_highlight%22%3Afalse%2C%22_src%22%3Atrue%7D%2C%22source%22%3A%22%23%20Foo%5Cn%23%23%20Bar%5Cn%3E%20%23%23%23%20Bla%5Cn%5CnBaz%5Cn%23%23%20Quux%5Cn%5Cn%3Csection%3E%5Cn%5Cn%23%23%23%20Thud%5Cn%5Cn%3C%2Fsection%3E%5Cn%5CnGrunt%22%7D) injection.

---

<div class="post-metadata">

**Author:** ![randomstuff](https://talk.commonmark.org/user_avatar/talk.commonmark.org/randomstuff/32/2993_2.png) [@randomstuff](https://talk.commonmark.org/u/randomstuff)\
**Post date:** [October 29, 2014, 2:54pm UTC](https://talk.commonmark.org/t/explicit-section-not-possible/796/3 "2014-10-29T14:54:53Z")

</div>

I would like to be able to type:

```
# Foo

## Bar

p

```

and have:

```
<h1>Foo</h1>
<section>
  <h1>Bar</h1>
  <p>p</p>
</section>

```

---

<div class="post-metadata">

**Author:** ![mb21](https://talk.commonmark.org/user_avatar/talk.commonmark.org/mb21/32/162_2.png) [@mb21](https://talk.commonmark.org/u/mb21)\
**Post date:** [October 29, 2014, 3:07pm UTC](https://talk.commonmark.org/t/explicit-section-not-possible/796/4 "2014-10-29T15:07:00Z")

</div>

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.

```
$ pandoc --section-divs -t html5
# Foo

## Bar

p

<section id="foo" class="level1">
<h1>Foo</h1>
<section id="bar" class="level2">
<h2>Bar</h2>
<p>p</p>
</section>
</section>

```

---

<div class="post-metadata">

**Author:** ![randomstuff](https://talk.commonmark.org/user_avatar/talk.commonmark.org/randomstuff/32/2993_2.png) [@randomstuff](https://talk.commonmark.org/u/randomstuff)\
**Post date:** [October 29, 2014, 10:38pm UTC](https://talk.commonmark.org/t/explicit-section-not-possible/796/5 "2014-10-29T22:38:09Z")

</div>

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.

From the hierachical AST, it is easy to uild the both the hierachical serialisation and the flat one.

---

<div class="post-metadata">

**Author:** ![mofosyne](https://talk.commonmark.org/user_avatar/talk.commonmark.org/mofosyne/32/1438_2.png) [@mofosyne](https://talk.commonmark.org/u/mofosyne)\
**Post date:** [October 30, 2014, 1:53am UTC](https://talk.commonmark.org/t/explicit-section-not-possible/796/6 "2014-10-30T01:53:14Z")

</div>

Attempting to place attributes to sections to allow for easier slideshow coding. [Metadata in documents - #15 by mofosyne](http://talk.commonmark.org/t/metadata-in-documents/721/15)

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.

---

<div class="post-metadata">

**Author:** ![jgm](https://talk.commonmark.org/user_avatar/talk.commonmark.org/jgm/32/1360_2.png) [@jgm](https://talk.commonmark.org/u/jgm)\
**Post date:** [October 30, 2014, 4:44am UTC](https://talk.commonmark.org/t/explicit-section-not-possible/796/7 "2014-10-30T04:44:24Z")

</div>

+++ Randomstuff [Oct 29 14 22:49]:

> 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:

```auto
# Foo

### Bar
p

```

```auto
# 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.

---

<div class="post-metadata">

**Author:** ![chrisalley](https://talk.commonmark.org/user_avatar/talk.commonmark.org/chrisalley/32/906_2.png) [@chrisalley](https://talk.commonmark.org/u/chrisalley)\
**Post date:** [November 6, 2014, 9:26am UTC](https://talk.commonmark.org/t/explicit-section-not-possible/796/8 "2014-11-06T09:26:48Z")

</div>

> [@diimdeep](#):
>
> Is explicit section is not possible in pure markdown ?

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.

---

<div class="post-metadata">

**Author:** ![mofosyne](https://talk.commonmark.org/user_avatar/talk.commonmark.org/mofosyne/32/1438_2.png) [@mofosyne](https://talk.commonmark.org/u/mofosyne)\
**Post date:** [November 6, 2014, 9:39am UTC](https://talk.commonmark.org/t/explicit-section-not-possible/796/9 "2014-11-06T09:39:22Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![chrisalley](https://talk.commonmark.org/user_avatar/talk.commonmark.org/chrisalley/32/906_2.png) [@chrisalley](https://talk.commonmark.org/u/chrisalley)\
**Post date:** [November 6, 2014, 11:43am UTC](https://talk.commonmark.org/t/explicit-section-not-possible/796/10 "2014-11-06T11:43:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![randomstuff](https://talk.commonmark.org/user_avatar/talk.commonmark.org/randomstuff/32/2993_2.png) [@randomstuff](https://talk.commonmark.org/u/randomstuff)\
**Post date:** [July 31, 2015, 9:59pm UTC](https://talk.commonmark.org/t/explicit-section-not-possible/796/11 "2015-07-31T21:59:13Z")

</div>

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.
