1 | [![NPM version](https://img.shields.io/npm/v/markdown-it-multimd-table.svg?style=flat)](https://www.npmjs.org/package/markdown-it-multimd-table)
|
2 | [![Build Status](https://travis-ci.org/RedBug312/markdown-it-multimd-table.svg?branch=master)](https://travis-ci.org/RedBug312/markdown-it-multimd-table)
|
3 | [![Coverage Status](https://coveralls.io/repos/github/RedBug312/markdown-it-multimd-table/badge.svg?branch=master)](https://coveralls.io/github/RedBug312/markdown-it-multimd-table?branch=master)
|
4 |
|
5 | MultiMarkdown table syntax plugin for markdown-it markdown parser
|
6 |
|
7 | ## Intro
|
8 |
|
9 | Markdown specs defines only the basics for tables. When users want common
|
10 | features like `colspan`, they must fallback to raw HTML. And writing tables in
|
11 | HTML is truly *lengthy and troublesome*.
|
12 |
|
13 | This plugin extends markdown-it with MultiMarkdown table syntax.
|
14 | [MultiMarkdown][mmd6] is an extended Markdown spec. It defines clear rules for
|
15 | advanced Markdown table syntax, while being consistent with original pipe
|
16 | table; [markdown-it][mdit] is a popular Markdown parser in JavaScript and
|
17 | allows plugins extending itself.
|
18 |
|
19 | [mmd6]: https://fletcher.github.io/MultiMarkdown-6/
|
20 | [mdit]: https://markdown-it.github.io/
|
21 |
|
22 | The features are provided:
|
23 | - Cell spans over columns
|
24 | - Cell spans over rows (optional)
|
25 | - Divide rows into sections
|
26 | - Multiple table headers
|
27 | - Table caption
|
28 | - Block-level elements such as lists, codes... (optional)
|
29 | - Omitted table header (optional)
|
30 |
|
31 | Noted that the plugin is not a re-written of MultiMarkdown. This plugin will
|
32 | behave differently from the official compiler, but doing its best to obey rules
|
33 | defined in [MultiMarkdown User's Guide][mmd6-table]. Please pose an issue if
|
34 | there are weird results for sensible inputs.
|
35 |
|
36 | [mmd6-table]: https://fletcher.github.io/MultiMarkdown-6/syntax/tables.html
|
37 |
|
38 | ## Usage
|
39 |
|
40 | ```javascript
|
41 | // defaults
|
42 | var md = require('markdown-it')()
|
43 | .use(require('markdown-it-multimd-table'));
|
44 |
|
45 | // full options list (equivalent to defaults)
|
46 | var md = require('markdown-it')()
|
47 | .use(require('markdown-it-multimd-table'), {
|
48 | multiline: false,
|
49 | rowspan: false,
|
50 | headerless: false,
|
51 | });
|
52 |
|
53 | md.render(/*...*/)
|
54 | ```
|
55 |
|
56 | For a quick demo:
|
57 | ```javascript
|
58 | $ mkdir markdown-it-multimd-table
|
59 | $ cd markdown-it-multimd-table
|
60 | $ npm install markdown-it-multimd-table --prefix .
|
61 | $ vim test.js
|
62 |
|
63 | var md = require('markdown-it')()
|
64 | .use(require('markdown-it-multimd-table'));
|
65 |
|
66 | const exampleTable =
|
67 | "| | Grouping || \n" +
|
68 | "First Header | Second Header | Third Header | \n" +
|
69 | " ------------ | :-----------: | -----------: | \n" +
|
70 | "Content | *Long Cell* || \n" +
|
71 | "Content | **Cell** | Cell | \n" +
|
72 | " \n" +
|
73 | "New section | More | Data | \n" +
|
74 | "And more | With an escaped '\\|' || \n" +
|
75 | "[Prototype table] \n";
|
76 |
|
77 | console.log(md.render(exampleTable));
|
78 |
|
79 | $ node test.js > test.html
|
80 | $ firefox test.html
|
81 | ```
|
82 |
|
83 | Here's the table expected on browser:
|
84 |
|
85 | <table>
|
86 | <thead>
|
87 | <tr>
|
88 | <th></th>
|
89 | <th align="center" colspan="2">Grouping</th>
|
90 | </tr>
|
91 | <tr>
|
92 | <th>First Header</th>
|
93 | <th align="center">Second Header</th>
|
94 | <th align="right">Third Header</th>
|
95 | </tr>
|
96 | </thead>
|
97 | <tbody>
|
98 | <tr>
|
99 | <td>Content</td>
|
100 | <td align="center" colspan="2"><em>Long Cell</em></td>
|
101 | </tr>
|
102 | <tr>
|
103 | <td>Content</td>
|
104 | <td align="center"><strong>Cell</strong></td>
|
105 | <td align="right">Cell</td>
|
106 | </tr>
|
107 | </tbody>
|
108 | <tbody>
|
109 | <tr>
|
110 | <td>New section</td>
|
111 | <td align="center">More</td>
|
112 | <td align="right">Data</td>
|
113 | </tr>
|
114 | <tr>
|
115 | <td>And more</td>
|
116 | <td align="center" colspan="2">With an escaped '|'</td>
|
117 | </tr>
|
118 | </tbody>
|
119 | <caption id="prototypetable">Prototype table</caption>
|
120 | </table>
|
121 |
|
122 | Noted that GitHub filters out `style` property, so the example uses `align` the
|
123 | obsolete one. However it outputs `style="text-align: ..."` in actual.
|
124 |
|
125 | ### Multiline (optional)
|
126 |
|
127 | Backslash at end merges with line content below.<br>
|
128 | Feature contributed by [Lucas-C](https://github.com/Lucas-C).
|
129 |
|
130 | ```markdown
|
131 | | Markdown | Rendered HTML |
|
132 | |--------------|---------------|
|
133 | | *Italic* | *Italic* | \
|
134 | | | |
|
135 | | - Item 1 | - Item 1 | \
|
136 | | - Item 2 | - Item 2 |
|
137 | | ```python | ```python \
|
138 | | .1 + .2 | .1 + .2 \
|
139 | | ``` | ``` |
|
140 | ```
|
141 |
|
142 | This is parsed below when the option enabled:
|
143 |
|
144 | <table>
|
145 | <thead>
|
146 | <tr>
|
147 | <th>Markdown</th>
|
148 | <th>Rendered HTML</th>
|
149 | </tr>
|
150 | </thead>
|
151 | <tbody>
|
152 | <tr>
|
153 | <td>
|
154 | <pre><code>*Italic*
|
155 | </code></pre>
|
156 | </td>
|
157 | <td>
|
158 | <p><em>Italic</em></p>
|
159 | </td>
|
160 | </tr>
|
161 | <tr>
|
162 | <td>
|
163 | <pre><code>- Item 1
|
164 | - Item 2</code></pre>
|
165 | </td>
|
166 | <td>
|
167 | <ul>
|
168 | <li>Item 1</li>
|
169 | <li>Item 2</li>
|
170 | </ul>
|
171 | </td>
|
172 | </tr>
|
173 | <tr>
|
174 | <td>
|
175 | <pre><code>```python
|
176 | .1 + .2
|
177 | ```</code></pre>
|
178 | </td>
|
179 | <td>
|
180 | <pre><code class="language-python">.1 + .2
|
181 | </code></pre>
|
182 | </td>
|
183 | </tr>
|
184 | </tbody>
|
185 | </table>
|
186 |
|
187 | ### Rowspan (optional)
|
188 |
|
189 | `^^` indicates cells being merged above.<br>
|
190 | Feature contributed by [pmccloghrylaing](https://github.com/pmccloghrylaing).
|
191 |
|
192 | ```markdown
|
193 | Stage | Direct Products | ATP Yields
|
194 | ----: | --------------: | ---------:
|
195 | Glycolysis | 2 ATP ||
|
196 | ^^ | 2 NADH | 3--5 ATP |
|
197 | Pyruvaye oxidation | 2 NADH | 5 ATP |
|
198 | Citric acid cycle | 2 ATP ||
|
199 | ^^ | 6 NADH | 15 ATP |
|
200 | ^^ | 2 FADH2 | 3 ATP |
|
201 | **30--32** ATP |||
|
202 | [Net ATP yields per hexose]
|
203 | ```
|
204 |
|
205 | This is parsed below when the option enabled:
|
206 |
|
207 | <table>
|
208 | <caption id="netatpyieldsperhexose">Net ATP yields per hexose</caption>
|
209 | <thead>
|
210 | <tr>
|
211 | <th align="right">Stage</th>
|
212 | <th align="right">Direct Products</th>
|
213 | <th align="right">ATP Yields</th>
|
214 | </tr>
|
215 | </thead>
|
216 | <tbody>
|
217 | <tr>
|
218 | <td align="right" rowspan="2">Glycolysis</td>
|
219 | <td align="right" colspan="2">2 ATP</td>
|
220 | </tr>
|
221 | <tr>
|
222 | <td align="right">2 NADH</td>
|
223 | <td align="right">3–5 ATP</td>
|
224 | </tr>
|
225 | <tr>
|
226 | <td align="right">Pyruvaye oxidation</td>
|
227 | <td align="right">2 NADH</td>
|
228 | <td align="right">5 ATP</td>
|
229 | </tr>
|
230 | <tr>
|
231 | <td align="right" rowspan="3">Citric acid cycle</td>
|
232 | <td align="right" colspan="2">2 ATP</td>
|
233 | </tr>
|
234 | <tr>
|
235 | <td align="right">6 NADH</td>
|
236 | <td align="right">15 ATP</td>
|
237 | </tr>
|
238 | <tr>
|
239 | <td align="right">2 FADH2</td>
|
240 | <td align="right">3 ATP</td>
|
241 | </tr>
|
242 | <tr>
|
243 | <td align="right" colspan="3"><strong>30–32</strong> ATP</td>
|
244 | </tr>
|
245 | </tbody>
|
246 | </table>
|
247 |
|
248 | ### Headerless (optional)
|
249 |
|
250 | Table header can be eliminated.
|
251 |
|
252 | ```markdown
|
253 | |--|--|--|--|--|--|--|--|
|
254 | |♜| |♝|♛|♚|♝|♞|♜|
|
255 | | |♟|♟|♟| |♟|♟|♟|
|
256 | |♟| |♞| | | | | |
|
257 | | |♗| | |♟| | | |
|
258 | | | | | |♙| | | |
|
259 | | | | | | |♘| | |
|
260 | |♙|♙|♙|♙| |♙|♙|♙|
|
261 | |♖|♘|♗|♕|♔| | |♖|
|
262 | ```
|
263 |
|
264 | This is parsed below when the option enabled:
|
265 |
|
266 | <table>
|
267 | <tbody>
|
268 | <tr>
|
269 | <td>♜</td>
|
270 | <td></td>
|
271 | <td>♝</td>
|
272 | <td>♛</td>
|
273 | <td>♚</td>
|
274 | <td>♝</td>
|
275 | <td>♞</td>
|
276 | <td>♜</td>
|
277 | </tr>
|
278 | <tr>
|
279 | <td></td>
|
280 | <td>♟</td>
|
281 | <td>♟</td>
|
282 | <td>♟</td>
|
283 | <td></td>
|
284 | <td>♟</td>
|
285 | <td>♟</td>
|
286 | <td>♟</td>
|
287 | </tr>
|
288 | <tr>
|
289 | <td>♟</td>
|
290 | <td></td>
|
291 | <td>♞</td>
|
292 | <td></td>
|
293 | <td></td>
|
294 | <td></td>
|
295 | <td></td>
|
296 | <td></td>
|
297 | </tr>
|
298 | <tr>
|
299 | <td></td>
|
300 | <td>♗</td>
|
301 | <td></td>
|
302 | <td></td>
|
303 | <td>♟</td>
|
304 | <td></td>
|
305 | <td></td>
|
306 | <td></td>
|
307 | </tr>
|
308 | <tr>
|
309 | <td></td>
|
310 | <td></td>
|
311 | <td></td>
|
312 | <td></td>
|
313 | <td>♙</td>
|
314 | <td></td>
|
315 | <td></td>
|
316 | <td></td>
|
317 | </tr>
|
318 | <tr>
|
319 | <td></td>
|
320 | <td></td>
|
321 | <td></td>
|
322 | <td></td>
|
323 | <td></td>
|
324 | <td>♘</td>
|
325 | <td></td>
|
326 | <td></td>
|
327 | </tr>
|
328 | <tr>
|
329 | <td>♙</td>
|
330 | <td>♙</td>
|
331 | <td>♙</td>
|
332 | <td>♙</td>
|
333 | <td></td>
|
334 | <td>♙</td>
|
335 | <td>♙</td>
|
336 | <td>♙</td>
|
337 | </tr>
|
338 | <tr>
|
339 | <td>♖</td>
|
340 | <td>♘</td>
|
341 | <td>♗</td>
|
342 | <td>♕</td>
|
343 | <td>♔</td>
|
344 | <td></td>
|
345 | <td></td>
|
346 | <td>♖</td>
|
347 | </tr>
|
348 | </tbody>
|
349 | </table>
|
350 |
|
351 | ## Credits
|
352 |
|
353 | * [MultiMarkdown][mmd6], Lightweight
|
354 | markup processor to produce HTML, LaTeX, and more.
|
355 | * [markdown-it][mdit], Markdown parser, done right.
|
356 | 100% CommonMark support, extensions, syntax plugins & high speed.
|
357 |
|
358 | ## License
|
359 |
|
360 | This software is licensed under the [MIT license][license] © RedBug312.
|
361 |
|
362 | [license]: https://opensource.org/licenses/mit-license.php
|