showdown icon indicating copy to clipboard operation
showdown copied to clipboard

Using Header Tags within Tables

Open SmartieCodes opened this issue 8 years ago • 5 comments

Header tags don't seem to work inside tables, is there a way to get them to work?

Example code:

# Header 1
## Header 2
### Header 3
#### Header 4
##### Header 5
###### Header 6
**bold**
*italic*

| # Header 1 |
| --- |
| ## Header 2 |
| ### Header 3 |
| #### Header 4 |
| ##### Header 5 |
| ###### Header 6 |
| **bold** |
| *italic* |

Additionally, is there a way to create a table without it using the <th> for the first row which formats the data as a table header?

SmartieCodes avatar Jul 27 '18 14:07 SmartieCodes

Header tags don't seem to work inside tables, is there a way to get them to work?

Using HTML directly inside tables.

| <h1>header1</h1> |
| --- |
| **bold** |
| *italic* |

Additionally, is there a way to create a table without it using the for the first row which formats the data as a table header?

No. We needed to standardize the table output and using thead and th seemed the semantically correct way,

tivie avatar Aug 05 '18 01:08 tivie

Ideally I don't want to tell our users to use HTML, that's the whole reason we're using markup 😄

SmartieCodes avatar Aug 07 '18 15:08 SmartieCodes

To add to the explanation, there are 2 reasons why you can't use headings inside tables.

According to the HTML living standard, the th element's content model only allows for "Flow content, but with no header, footer, sectioning content, or heading content descendants." This means h1 isn't allowed inside th elements. So this...

| # Header 1 |
| --- |
| foo |

would result in non compliant generated HTML.

The other reason is that headings, in markdown, are treated as block elements (not span/inline elements). Block elements require, at least, one line break (\n) or a EOF at the end.

Due to the nature of markdown tables' syntax, this is not possible, and that's the reason why only inline/span markdown elements are allowed in markdown's table cells.

Please note that, concerning HTML spec, and contrary to th elements, heading elements are perfectly valid in table bodies (td elements). So you can "cheat" around this using HTML directly.

As a final note, I don't know of any other markdown specification or implementation that allows headings in tables.

tivie avatar Aug 08 '18 00:08 tivie

Thank you for the reply, I hadn't realised having headers inside tables was a "bad" thing. Will have think around this.

SmartieCodes avatar Aug 08 '18 08:08 SmartieCodes

I will be closing this issue. If you feel there's something else you wish to add, please feel free to reopen it.

tivie avatar Sep 14 '18 18:09 tivie