1

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

Renato Gama
  • 16,431
  • 12
  • 58
  • 92
  • What troubles are you having making it yourself? Seems like it is a split and looping. – epascarello Sep 10 '12 at 14:08
  • I tried implementing the the table parser myself - modifing the string before sending to showdown: I could parse the table but everytime got caught in syntax exceptions that was difficult to handle - I tried sending the string first to a wiki parser that has this feature, but It messed up the rest of the string so showdown couldnt parse it correctly - would have any suggestion on how to solve this??? – Renato Gama Sep 10 '12 at 14:12

2 Answers2

2

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! :)

Juho Vepsäläinen
  • 26,573
  • 12
  • 79
  • 105
  • 1
    Apparently marked should work in browser too. Here's another attempt at table syntax btw: https://github.com/chjj/marked/pull/74 . – Juho Vepsäläinen Sep 10 '12 at 15:02
  • Good to know that! I'll need a markdown parser that runs in the browser for adding 'live markdown editor' (like mouapp for Mac OS X) to my LIVEditor (http://liveditor.com) – Edwin Yip Jul 18 '13 at 05:43
  • marked should work in browsers. It supports GitHub table syntax these days even. – Juho Vepsäläinen Jul 18 '13 at 07:12
1

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.

Tivie
  • 18,864
  • 5
  • 58
  • 77
Kus
  • 2,529
  • 27
  • 27