hammerdown
Streaming html to markdown writer
Get Started
Checkout The Live Demo here!
Simple Example
var hammerdown = ; //HTMLvar htmlToConvert = = "<h1>A Markdown Header</h1><p>Some text <b>bold text</b></p>" //Write markdown ; //Outputs// # A Markdown Header//// Some text **bold text**
Simple Example with streams
var hammerdown = ; //HTMLvar htmlToConvert = = "<h1>A Markdown Header</h1><p>Some text <b>bold text</b></p>" //Write markdown; //Outputs// # A Markdown Header//// Some text **bold text**
Installation
npm Install
npm install hammerdown
Browser Install
bower install hammerdown
NOTE: If using in the browser use the following:
//HTMLvar htmlToConvert = = "<h1>A Markdown Header</h1><p>Some text <b>bold text</b></p>" ;
Github Flavored Markdown Example
var hammerdown = ; //Write markdownvar htmlString = "<pre>" + "<code class='language-javascript'>"+ "var awesomeoFunction = function(){"+ "return true;"+ "}"+ "</code>"+ "</pre>";; //Outputs// ```javascript// function myFunction(params){return true;};// ```
Purpose
Existing html to markdown writers didn't:
- Support windows easily (html.md)
- Lack of support for github flavored markdown (to-markdown)
- Didn't support streams
Why convert html to markdown?
To have an easy way to programatically generate a stream of markdown text from html. This library includes converters for standard markdown and it also includes Github-Flavored-Markdown definitions.
Markdown is a mechanism to create documents. See for more details. Hammerdown allows developers to leverage the simplicity of Markdown from html text.
Gulp Plugin!
For adding to your build process checkout gulp-hammerdown
Options
Hammerdown currently accepts one option: type
. If type
is "gfm"
then hammerdown will produce markdown using github flavored markdown(gfm).
Examples
Below is a select group of examples. More examples can be found by looking at the integration tests.
Github Flavored Markdown Examples
Simple Example using file stream
var fs = ;var hammerdown = ; var htmlFileStream = fs; //Output markdownhtmlFileStream; //Outputs// # Any header // // Any **Content**
<!-- anyHtmlFile.html--> Any Title Any header Any Content
Tables
var fs = var hammerdown = ; var htmlFileStream = fs; //Output markdownhtmlFileStream; //Outputs// |Header1|Header1|// |---|---|// |row1-col1|row1-col2|// |row2-col1|row2-col2|
<!-- anyTable.html --> Table Html Header1 Header1 row1-col1 row1-col2 row2-col1 row2-col2
Fenced Code Block
var fs = var hammerdown = ; var htmlFileStream = fs; //Output markdownhtmlFileStream; //Outputs// ```javascript// var awesomeoFunction = function(){// return true;// };// ```
<!-- anyFencedCodeBlock.html --> Fenced Code Block var awesomeoFunction = function(){ return true; };
Credits and other frameworks
-
Thanks to karlcows Markdown Test Runner I was able to provide a solid set of tests
-
to_markdown another good html to markdown tool by domchristie