Searching a JavaScript library that should convert HTML code to Markdown format.

It should have the following features:

  • convert basic HTML tags to Markdown (h1...6, pre, code etc)
  • keep the HTML code if it hasn't a correspondent in Markdown (e.g. iframe)
  • work on server side (NodeJS)
  • work on client side (browser)

First three points are important for me, but any recs/suggestions are welcome.


HTML                                    | Converted
<h1>Hello World</h1>                    | # Hello World
<h1 class="foo">Hello World</h1>        | <h1 class="foo">Hello World</h1>
<p>Lorem ipsum</p>                      | Lorem ipsum
<p data-something="foo">Lorem ipsum</p> | <p data-something="foo">Lorem ipsum</p>
<img src="something">                   | ![](something)
<a href="...">foo</a>                   | [foo](...)
<a disabled="" href="...">foo</a>       | <a disabled="" href="...">foo</a>
  • 1
    Would you be interested in a Server side only option? I don't know of any that are both or just browser side but I do know of one that is Server side. Jun 29, 2014 at 8:32
  • @NickWilde That would be perfect. If it works on server side, it should work on client side as well. Thanks! Jun 29, 2014 at 8:42
  • 1
    I would recommend the to-markdown on github. > An HTML to Markdown converter written in JavaScript
    – junedkazi
    Aug 10, 2014 at 19:13

1 Answer 1


Usually I really like Pandoc for all my text format conversion needs. However it is Haskell based - though it does have easy install/executable options for most OSes. Of course it can't be run via JavaScript very well - Sure you can work something up with Node.js and streams; but why bother when it has already been done: Jandoc.

Jandoc does everything Pandoc does but with (Node.js) JavaScript wrappers.

Installation is slightly complicated;

  1. Install Node.js
  2. Install the Haskell Platform.
  3. Run cmd prompt and execute cabal update (that doesn't update cabal just the package source listing, to update cabal (if desired/needed) run cabal install cabal-install)
  4. cmd prompt: cabal install pandoc (It'll take a while)
  5. cmd prompt: npm install jandoc -g

API information is in the Jandoc Readme.

To go over your requirements:

  • convert basic HTML tags to Markdown (h1...6, pre, code etc): Yes
  • keep the HTML code if it hasn't a correspondent in Markdown (e.g. iframe): Yes - if using the -R/--parse-raw option. So for Jandoc via the JavaScript API you'd just include a parseRaw: True argument in your options list.
  • work on server side (Node.JS): Yes
  • work on client side (browser): NO. Not easily portable to browser usage either.
  • 1
    One could possibly use the haste-compiler to convert from Haskell to ECMAScript, but I doubt that this task will be easy.
    – ComFreek
    Jun 30, 2014 at 15:51
  • Yeah I'm sure it could be done but honestly to just support html->md it would be much simpler to just do it from scratch with a few regexp replacements. Jun 30, 2014 at 18:01
  • 1
    Hey Nick, thank you for answer. I will review it soon, but I am busy with the baccalaureate exams. Jul 2, 2014 at 10:51
  • @NickWilde If that's possible with some simple regular expressions, I would choose that way. I'm testing haskell way. Aug 10, 2014 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.