evilstreak / markdown-js

A Markdown parser for javascript
7.69k stars 863 forks source link

Support for Tables #230

Open NomNuggetNom opened 9 years ago

NomNuggetNom commented 9 years ago

It'd be really cool if some support for tables could be added, like GitHub's Markdown supports.

mustmodify commented 9 years ago

There is some support for tables. In the tests,

My reading of this is that you have to use the non-default "Maruku" dialect for it to work: https://github.com/evilstreak/markdown-js/blob/master/test/features.t.js#L73-L74

and after some experimentation, I was able to get it to work:

z = "Entity      | Result\n------------|----------\n`©`    |  ©\n`£`   |  £\n`a b`  |  a b\n`λ`  |  λ\n`—`   |  &mdash";
markdown.toHTML(z, 'Maruku');

results in

<table><thead><tr><th>Entity</th><th>Result</th></tr></thead><tbody><tr><td><code>&amp;copy;</code></td><td>&amp;copy;</td></tr><tr><td><code>&amp;pound;</code></td><td>&amp;pound;</td></tr><tr><td><code>a&amp;nbsp;b</code></td><td>a&amp;nbsp;b</td></tr><tr><td><code>&amp;lambda;</code></td><td>&amp;lambda;</td></tr><tr><td><code>&amp;mdash;</code></td><td>&amp;mdash</td></tr></tbody></table>