Is there javascript to convert HTML to markdown? [closed]
There is showdown.js to convert markdown to HTML, and PHP Markdown to convert markdown to and from HTML. My question is, is there javascript library to convert HTML to markdown?
I've started a project to do this:
https://github.com/domchristie/turndown
It's still in its early stages, so has not been heavily tested, but it's a start.
Feedback/contributions welcome.
I have also collaborated on a project on github that does this. At this moment, it is only tested in browser.
html2markdown
I have done a lot of testing on web. Added ton of unit tests. Still not perfect but works nicely. Feedback welcome and I will be happy to receive pull requests or fix any defects you find.
Theoretically, you can convert it back. You'd have to write your own DOM traversal code and convert the HTML back to Markdown.
Generally Markdown is thought to be the human readable/writable source of the information that is converted to HTML for further markup and styling.
HTML can be much more complex than Markdown and can be indefinitely nested and partitioned into tags. This is why it's so questionable to write a general purpose converter which reliably converts HTML back to Markdown. Just imagine all the whitespace and paragraphs going bye-bye and possibly causing a terrible mess for the human eye.
My suggestion is: Unless you generate originating HTML yourself and know what it consists of, don't convert it back to Markdown. Keep the Markdown version all the time and convert to HTML when needed.
Although not a markdown converter, wiky does a decent job in converting HTML to wiki markup and vice versa.
This is written in JS and does the conversion in just one line. This does a decent job in converting HTML obtained from a WYSIWYG editor to wiki markup which can then be passed over to backend for further processing.
Well as commented before not all HTML tags can be converted, therefore you might have to strip or escape those HTML tags before saving.
精彩评论