Is there any Markdown syntax parser for JavaScript with table?

4.5k Views Asked by At

I am looking for a Markdown syntax JavaScript parser with the table feature. It seems that I cant find one so I am having the hassle of implementing this feature into existing code, but I am not being able to do so. Does anyone know a JavaScript library that parses MULTIMARKDOWN or at least a not so difficult way to implement the table feature?

By table feature I mean a syntax to be transformed in an HTML table, for example:

|= header1 |= hader2
| cell 1 | cell 2

would become

<table>
    <tr>
        <th>
             header1
        </th>
        <th>
             header2
        </th>
    </tr>
    <tr>
        <td>
             cell1
        </td>
        <td>
             cell2
        </td>
    </tr>
</table>

So far I have even tried mixing a Wiki parser with Markdown parser with no success.

EDIT: I need it to run on the browser not for node.js

2

There are 2 best solutions below

1
On

Showdown which is a JavaScript port of Markdown, and use the table extension.

I ran into a problem with loading the table plugin: Uncaught Extension 'undefined' could not be loaded. It was either not found or is not a valid extension. this can be fixed by loading the extension this way: var converter = new showdown.Converter({ extensions: ['table'] }); as pointed out here.

There is another bug if you have multiple tables on the one document it repeats them, the fix for that is here.

3
On

I have an implementation of GitHub table syntax at ghw. Feel free to use that if you want. Note that it depends on marked.

Hope that helps! :)