Separate parser library
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.
+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
+++ 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.
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!
+++ 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.
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:
+++ 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.
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.
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').