0

I have a question and this one might not even be relevant, but I would like to know if this is possible.

I'm building an open-source CMS written in Node.js called Spectrum. I have come across this awesome Markdown Parser called Kramdown The beautiful thing with this parser is that it works with Markdown, Markup and extra cool stuff and I really want to have this in my Node.js app.

I have zero knowledge about Ruby and this is my first time touching it.

I finally got the app running followed this Demo.

Now I want this editor to be able to interact with my node.js app.

If the user visit this route:

http://localhost:3000/new-post

The editor will be render and the user can enter some content and publish this directly.

If the user visit this route:

http://localhot:3000/hello-world/edit

It should render the editor with some content, and that content is being sent by node.js which retrieved from the database.

Can I do something crazy like this?

Reason why I want this kramdown on my CMS.

I was looking for the best Markdown editor/parser for my CMS and really I have spent a lot of times on researching already and never found anything that really can tell me that this is what I want until I found Kramdown.

I have tried Pagedown

It was good, but missing a lot of features, so I found

PageDown Extra, and it is still missing some of what I really want in it.

I found one of the best "Editor" Stackedit, but this is way too heavy and have too many features that really making my editor going way too slow to be used.

Then I start writing my own Markdown parser using Regex passion coming from this blog post, but really that is going to take me a lot of times because I'm not an expert with Regex but I'm getting the hang of it.

I've also tried Marked

So what I really want now is. Any editor/parser that can do something similar to Kramdown and can be integrated with my node.js app.

Ali
  • 9,997
  • 20
  • 70
  • 105
  • kramdown is just a parser gem, kramdown-demo seems to be an app using kramdown. karmdown file_to_be_converted will give you html o/p. Is that what you need? If so I will detail it out.. :) – egghese Jul 19 '13 at 15:24
  • I will update my question a bit of why I want this @JeslyVarghese – Ali Jul 19 '13 at 15:25
  • @JeslyVarghese I updated my question here. – Ali Jul 19 '13 at 15:42
  • have you tried [marked](https://github.com/chjj/marked)? – Akshat Jiwan Sharma Jul 19 '13 at 15:45
  • @AkshatJiwanSharma yes I did, and actually I have tried more :( – Ali Jul 19 '13 at 15:46
  • @Ali: Can you execute shell scripts from a node.js app? if so, why not take the o/p of kramdown and use it in your app directly? – egghese Jul 19 '13 at 16:32
  • @JeslyVarghese this is what I found. http://stackoverflow.com/questions/7464036/node-js-shell-script-and-arguments – Ali Jul 19 '13 at 16:38
  • @Ali: :) am all alien to js as well as node.js. I guess thats the soln you want. why not try it with kramdown, you need to install kramdown gem first, then kramdown filename.md. you will get your parsed html as o/p – egghese Jul 19 '13 at 16:40
  • @JeslyVarghese do you mind giving some example? as I'm new to Node.js and zero to Ruby. I would be really appreciated if you can get me started with this. Like I did have kramdown installed and running the way how Kramdown Demo works now, but not sure how this going to work with node.js – Ali Jul 19 '13 at 16:43
  • 1
    @Ali: Am a zero in node.js ;). Still try this http://pastie.org/8156135 – egghese Jul 19 '13 at 16:52
  • I was about to post that too :P It's great! Thanks... you can post the answer here so people can also benefit (I hope) :D – Ali Jul 19 '13 at 16:53
  • 1
    @Ali: it works? if so, i will :) – egghese Jul 19 '13 at 17:11

1 Answers1

3

Kramdown is a parser gem, and like bundler it can be called from commandline.

Kramdown takes markdown or any of its superset as an input parameter and spits out html/latex/kramdown as o/p.

Without any options the default output is HTML and that's the desired o/p in this case. So we just need to call kramdown from shell from the node.js app (if kramdown gem is installed, if not $gem install kramdown).

Here is what I guess it should be done in node.js. (I have zero knowledge in node.js, if there is something like ffi available to interface with ruby? if so its the better option than calling it from shell).

   var util = require('util'),
   exec = require('child_process').exec,
   child;

   child = exec('kramdown '+markdownFile, // command line argument directly in string
   function (error, stdout, stderr) {      // one easy function to capture data/errors
   if (error !== null) {
     //use stdout var, it contains the desired o/p
    }
   });

The courtesy of this script is: Node.js Shell Script And Arguments.

To know other options available in kramdown

$kramdown --help
Community
  • 1
  • 1
egghese
  • 2,193
  • 16
  • 26