hammerdown
Streaming HTML To Markdown Writer
Last updated 5 years ago by tjchaplin .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install hammerdown 
SYNC missed versions from official npm registry.

hammerdown

Build Status

Streaming html to markdown writer

Get Started

Checkout The Live Demo here!

Simple Example

var hammerdown = require("hammerdown");

//HTML
var htmlToConvert = = "<h1>A Markdown Header</h1><p>Some text <b>bold text</b></p>"

//Write markdown 
hammerdown().parse(htmlToConvert,function(error, markdown){
	if(error) 
		throw error;

	console.log(markdown);
});

//Outputs
//	# A Markdown Header
//
//	Some text **bold text**

Simple Example with streams

var hammerdown = require("hammerdown");

//HTML
var htmlToConvert = = "<h1>A Markdown Header</h1><p>Some text <b>bold text</b></p>"

//Write markdown
hammerdown().parse(htmlToConvert).pipe(process.stdout);

//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:

//HTML
var htmlToConvert = = "<h1>A Markdown Header</h1><p>Some text <b>bold text</b></p>"

hammerdown().parse(htmlToConvert,function(error, markdown){
	if(error) 
		throw error;

	console.log(markdown);
});

Github Flavored Markdown Example

var hammerdown = require("hammerdown");

//Write markdown
var htmlString = "<pre>" +
					"<code class='language-javascript'>"+
						"var awesomeoFunction = function(){"+
							"return true;"+
						"}"+
					"</code>"+
				"</pre>";
hammerdown({type:"gfm"}).parse(htmlString).pipe(process.stdout);

//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 = require('fs');
var hammerdown = require('hammerdown');

var htmlFileStream = fs.createReadStream("anyHtmlFile.html");

//Output markdown
htmlFileStream.pipe(hammerdown()).pipe(process.stdout);

//Outputs
//  # Any header	
//  
//  Any **Content**
<!-- anyHtmlFile.html-->
<!doctype html>
<html>
<head>
	<title>Any Title</title>
</head>
<body>
	<h1>Any header</h1>
	<p>Any <b>Content</b></p>
</body>
</html>

Tables

var fs = require('fs')
var hammerdown = require('hammerdown');

var htmlFileStream = fs.createReadStream("anyTable.html");

//Output markdown
htmlFileStream.pipe(hammerdown({type:"gfm"})).pipe(process.stdout);

//Outputs
//  |Header1|Header1|
//  |---|---|
//  |row1-col1|row1-col2|
//  |row2-col1|row2-col2|
<!-- anyTable.html -->
<!doctype html>
<html>
	<head>
		<title>Table Html</title>
	</head>
	<body>
		<table>
			<tr>
				<th>
					Header1
				</th>
				<th>
					Header1
				</th>
			</tr>
			<tr>
				<td>
					row1-col1
				</td>
				<td>
					row1-col2
				</td>
			</tr>
			<tr>
				<td>
					row2-col1
				</td>
				<td>
					row2-col2
				</td>
			</tr>
		</table>
	</body>
</html>

Fenced Code Block

var fs = require('fs')
var hammerdown = require('hammerdown');

var htmlFileStream = fs.createReadStream("anyTable.html");

//Output markdown
htmlFileStream.pipe(hammerdown({type:"gfm"})).pipe(process.stdout);

//Outputs
//  ```javascript
//  var awesomeoFunction = function(){
//				return true;
//	};
//  ```
<!-- anyFencedCodeBlock.html -->
<!doctype html>
<html>
	<head>
		<title>Fenced Code Block</title>
	</head>
	<body>
		<pre>
		<code class='language-javascript'>
			var awesomeoFunction = function(){
				return true;
			};
		</code>
		</pre>
	</body>
</html>

Credits and other frameworks

Current Tags

  • 2.0.1                                ...           latest (5 years ago)

24 Versions

  • 2.0.1                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
  • 0.0.19                                ...           5 years ago
  • 0.0.18                                ...           6 years ago
  • 0.0.17                                ...           6 years ago
  • 0.0.16                                ...           6 years ago
  • 0.0.15                                ...           6 years ago
  • 0.0.14                                ...           6 years ago
  • 0.0.13                                ...           6 years ago
  • 0.0.12                                ...           6 years ago
  • 0.0.11                                ...           6 years ago
  • 0.0.10                                ...           6 years ago
  • 0.0.9                                ...           6 years ago
  • 0.0.8                                ...           6 years ago
  • 0.0.7                                ...           6 years ago
  • 0.0.6                                ...           6 years ago
  • 0.0.5                                ...           6 years ago
  • 0.0.4                                ...           6 years ago
  • 0.0.3                                ...           6 years ago
  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 24
Dependencies (4)
Dev Dependencies (12)

Copyright 2014 - 2016 © taobao.org |