Skip to content

Commit 0417987

Browse files
authored
Document Markdown table syntax (#4718)
Co-authored-by: Will <>
1 parent fcff34a commit 0417987

File tree

1 file changed

+47
-43
lines changed
  • files/en-us/mdn/contribute/markdown_in_mdn

1 file changed

+47
-43
lines changed

files/en-us/mdn/contribute/markdown_in_mdn/index.html

+47-43
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ <h2>Baseline: GitHub-Flavored Markdown</h2>
2222

2323
<p>The baseline for MDN Markdown is GitHub-Flavored Markdown (GFM): <a href="https://github.github.com/gfm/">https://github.github.com/gfm/</a>. This means that for anything not otherwise specified in this page, you can refer to the GFM specification. GFM in turn is a superset of CommonMark (<a href="https://spec.commonmark.org/">http://spec.commonmark.org/</a>).</p>
2424

25-
<p>GFM and CommonMark describe some extensions to <a href="https://daringfireball.net/projects/markdown/syntax">the original Markdown description</a>). We'll highlight two that are going to be important to us.
26-
27-
<h3>Code fences and info strings</h3>
25+
<h2>Example code blocks</h2>
2826

2927
<p>In GFM and CommonMark, authors can use "code fences" to demarcate <code>&lt;pre&gt;</code> blocks. The opening code fence may be followed by some text that is called the "info string". From the spec:</p>
3028

@@ -40,39 +38,7 @@ <h3>Code fences and info strings</h3>
4038
```
4139
</pre>
4240

43-
<h3>Tables</h3>
44-
45-
<p>In GFM (but not CommonMark) there is a syntax for tables: <a href="https://github.github.com/gfm/#tables-extension-">https://github.github.com/gfm/#tables-extension-</a>. We will make use of this but it should be noted that this syntax imposes limitations on the kinds of tables we can write, so in many cases this syntax will not be appropriate and we will need alternative ways of authoring tables.</p>
46-
47-
<p>In particular:</p>
48-
49-
<ul>
50-
<li>GFM tables must have a header row.</li>
51-
<li>GFM tables may not have a header column.</li>
52-
<li>GFM won't parse GFM block elements in table cells.</li>
53-
</ul>
54-
55-
<p>This last point means that if you write:</p>
56-
57-
<pre>
58-
--------------------------------------
59-
| i'm a test | yes i am |
60-
|----------------|-------------------|
61-
| `inline` is ok | * lists aren't |
62-
--------------------------------------
63-
</pre>
64-
65-
<p>...then the attempt to write a list in the bottom-right cell will just generate <code>&lt;td&gt;* lists aren't&lt;/td&gt;</code> in the output.</p>
66-
67-
68-
<h2>Extensions to GFM</h2>
69-
70-
<p>In this section we'll outline ways in which writers will be able to go beyond the syntax defined in the GFM spec.</p>
71-
72-
73-
<h3>Example code blocks</h3>
74-
75-
Writers will use code fences for example code blocks. They must specify the language of the code sample using the first word of the info string, and this will be used to provide syntax highlighting for the block. The following words will be supported:
41+
In MDN, writers will use code fences for example code blocks. They must specify the language of the code sample using the first word of the info string, and this will be used to provide syntax highlighting for the block. The following words will be supported:
7642

7743
<ul>
7844
<li><code>bash</code></li>
@@ -113,7 +79,7 @@ <h3>Example code blocks</h3>
11379
```
11480
</pre>
11581

116-
<h3>Notes, warnings, and callouts</h3>
82+
<h2>Notes, warnings, and callouts</h2>
11783

11884
<p>Sometimes writers want to call special attention to some piece of content. To do this, they will use a GFM blockquote with a special first paragraph. There are three types of these: notes, warnings, and callouts.</p>
11985

@@ -258,17 +224,55 @@ <h5>Note containing a code block</h5>
258224
<p>Like that.</p>
259225
</div>
260226

261-
<h3>Definition lists</h3>
227+
<h2>Definition lists</h2>
262228

263-
<h3>Tables</h3>
229+
<h2>Tables</h2>
230+
231+
<p>In GFM (but not CommonMark) there is a syntax for tables: <a href="https://github.github.com/gfm/#tables-extension-">https://github.github.com/gfm/#tables-extension-</a>. We will make use of this but the GFM syntax only supports a subset of the features available in HTML.</p>
232+
233+
<p>So the general principle here is: authors should use the GFM Markdown syntax when they can, and fall back to raw HTML when they have to.</p>
234+
235+
<p>The main limitations of GFM table syntax are:</p>
236+
237+
<ul>
238+
<li>GFM tables must have a header row.</li>
239+
<li>GFM tables may not have a header column.</li>
240+
<li>GFM won't parse GFM block elements in table cells. For example, you can't have a list in a table cell.</li>
241+
<li>GFM doesn't support any table elements beyond <code>&lt;table&gt;</code>, <code>&lt;tr&gt;</code>, and <code>&lt;th&gt;</code>, and <code>&lt;td&gt;</code>.</li>
242+
<li>GFM doesn't support any table element attributes like <code>colspan</code>, <code>rowspan</code>, or <code>scope</code>.</li>
243+
</ul>
244+
245+
<p>If an author needs to use any of the unsupported features, they should write the table in HTML.</p>
246+
247+
<p>We don't recommend the general use of <code>&lt;caption&gt;</code> elements on tables, since that would also rule out the GFM syntax.</p>
248+
249+
<p>In GFM table syntax, authors can omit leading and trailing pipes for rows. MDN authors must include these pipes, for the sake of readability.</p>
250+
251+
<p>That is, MDN authors must use this style:</p>
252+
253+
<pre>
254+
| Heading 1 | Heading 2 | Heading 3 |
255+
|-----------|-----------|-----------|
256+
| cell 1 | cell 2 | cell 3 |
257+
| cell 4 | cell 5 | cell 6 |
258+
</pre>
259+
260+
<p>and not this style:</p>
261+
262+
<pre>
263+
Heading 1 | Heading 2 | Heading 3
264+
--- | --- | ---
265+
cell 1 | cell 2 | cell 3
266+
cell 4 | cell 5 | cell 6
267+
</pre>
264268

265-
<h3>Heading IDs</h3>
269+
<h2>Heading IDs</h2>
266270

267-
<h3>Live samples</h3>
271+
<h2>Live samples</h2>
268272

269-
<h3>Inline styles</h3>
273+
<h2>Inline styles</h2>
270274

271-
<h3>KumaScript</h3>
275+
<h2>KumaScript</h2>
272276

273277
<p>Writers will be able to include KumaScript macro calls in prose content:</p>
274278

0 commit comments

Comments
 (0)