commonmark.js icon indicating copy to clipboard operation
commonmark.js copied to clipboard

Separate parser library

Open xxgreg opened this issue 10 years ago • 8 comments

I've been using the commonmark.js parser combined with react for rendering.

Since I am not using the html or xml renderer, it would be great to have a separate js file built which only contains the parser, node, and walker objects.

xxgreg avatar Sep 15 '15 00:09 xxgreg

+1. I am creating an HTML to markdown converter which should be 100% CommonMark compliant. I'm also only using the parser, node, and walker objects for now. EDIT: I'm just getting started but this is the github link: https://github.com/nicojs/html2commonmark

nicojs avatar Dec 01 '15 08:12 nicojs

+++ Nico Jansen [Dec 01 15 00:58 ]:

+1. I am creating an HTML to markdown converter which should be 100% CommonMark compliant. I'm also only using the parser, node, and walker objects for now.

Note that the C implementation (jgm/cmark) already has a really carefully written commonmark renderer. It would not be difficult to port this over to commonmark.js, and then you could use that for your HTML to markdown converter.

jgm avatar Dec 01 '15 21:12 jgm

Note that the C implementation (jgm/cmark) already has a really carefully written commonmark renderer. It would not be difficult to port this over to commonmark.js, and then you could use that for your HTML to markdown converter.

I think you are referring to the cmark_renderer. I am not a hero when it comes to c programming, but this will certainly be very interesting. Indeed markdown rendering is something i need. Thanks for the advice!

nicojs avatar Dec 02 '15 11:12 nicojs

+++ Nico Jansen [Dec 02 15 03:26 ]:

Note that the C implementation (jgm/cmark) already has a
really carefully written commonmark renderer. It would not
be difficult to port this over to commonmark.js, and then
you could use that for your HTML to markdown converter.

I think you are referring to the cmark_renderer. I am not a hero when it comes to c programming, but this will certainly be very interesting. Indeed markdown rendering is something i need. Thanks for the advice!

I'm referring to this: https://github.com/jgm/cmark/blob/master/src/commonmark.c

It uses some library code in https://github.com/jgm/cmark/blob/master/src/render.c

Since the js and C renderers both use a similar "walk" interface to walk the AST, it should be possible to do a fairly straightforward translation.

jgm avatar Dec 02 '15 19:12 jgm

Big fan of this, I'd love to be able to use the AST to handle TeX nodes similar to the other awesome @jgm project, pandoc. :smile:

rgbkrk avatar Jan 05 '16 22:01 rgbkrk

+++ Kyle Kelley [Jan 05 16 14:14 ]:

Big fan of this, I'd love to be able to use the AST to handle TeX nodes similar to the other awesome [1]@jgm project, pandoc. :smile:

You can already get the AST from commonmark.js. The only rationale I see for a separate parser library is to have a smaller library to import, without the renderers.

jgm avatar Jan 05 '16 23:01 jgm

Ah, ok. I'm not worried about size too much since I'm working on an Electron app. Mostly need to know what to rely on for TeX.

rgbkrk avatar Jan 06 '16 00:01 rgbkrk

One easy way to do this would be to have an official parser-only entrypoint

If you create a file in the root of the repo called parser-only.js

module.exports.version = '0.24.0'
module.exports.Parser = require('./blocks');

Then commonJS module bundlers will only pull these in when someone does require('commonmark/parser-only').

glenjamin avatar Apr 07 '16 15:04 glenjamin