markedjs / marked

A markdown parser and compiler. Built for speed.
https://marked.js.org
Other
32.97k stars 3.39k forks source link

Mark tables as "table" instead of "paragraph" at lexer? #40

Closed bebraw closed 12 years ago

bebraw commented 12 years ago

Hi,

Would it be possible for you to mark tables using "table" instead of "paragraph" at the lexer? This would make my work a lot easier. I use your lexer to apply some custom transformations to the source and then output as HTML using your parser. Having tables marked properly would make my life a lot easier. :)

chjj commented 12 years ago

What do you mean by table? I figure you're referring to the html element, but those are considered html blocks by the lexer.

bebraw commented 12 years ago

Hi,

Thanks for the swift reply and sorry for being unclear. Here's an an example of what I'm talking about. I guess the GitHub guys must be using some custom table plugin.

I'm not sure if this is something you should support natively. If you think so, great. Otherwise I probably could use some nice extension mechanism to hook into the lexer to avoid certain nastiness.

chjj commented 12 years ago

This is something people have been asking for. It might be good to keep everything contained in one issue: https://github.com/chjj/marked/issues/27 .

bebraw commented 12 years ago

Gotcha.

I noticed you that had done some experiments with an extension API. Any timeline on this? I don't mind helping out a bit if you can point out how. I really wouldn't mind getting those tables to work properly. :)

chjj commented 12 years ago

The extension API might not happen. The more I think about it, the more unrealistic it is. Take for instance the text regex for the inline rules: text: /^[^\0]+?(?=[\\<!\[_*]| {2,}\n|$)/`. If any inline rule is ever added, this regex needs to be updated accordingly to work properly. There's a lot of other little annoyances that would make it difficult. But, eventually, f I can dream up a nice clean interface to make marked extensible, without hurting performance, I will do it.

bebraw commented 12 years ago

Do you think some kind of hierarchical scheme would work? As I mentioned earlier tables get parsed as "paragraphs" now. If there was a way to attach another lexer to the context of paragraph it would do the trick I think.

This is sort of what I do in my current solution at ghw. I just check if the lexer gives my a text or a paragraph and then apply my rules in a certain order. Actually now that I think of it I can probably hack tables there using the same scheme. Need to give that a go to see how ugly it gets. :)

Thanks for the feedback. :)