# hammerdown

> Streaming HTML To Markdown Writer

Latest version **2.0.1** (published 2015-01-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install hammerdown
pnpm add hammerdown
yarn add hammerdown
bun add hammerdown
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2015-01-27 |
| First published | 2014-03-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 14 |
| Author | tjchaplin |
| Maintainers | tjchaplin |
| Keywords | html, markdown, md, tomarkdown, html-md, converter, hammerdown, stream, converter, hammer, writer, fluent |

## Links

- npm: https://www.npmjs.com/package/hammerdown
- Repository: https://github.com/tjchaplin/hammerdown
- Issues: https://github.com/tjchaplin/hammerdown/issues
- npm.io page: https://npm.io/package/hammerdown

## Dependencies (4)

- [sax](https://npm.io/package/sax.md) ~0.6.1
- [through](https://npm.io/package/through.md) ~2.3.6
- [trumpet](https://npm.io/package/trumpet.md) ~1.7.0
- [concat-stream](https://npm.io/package/concat-stream.md) 1.4.7

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 2.0.1 (latest) — 2015-01-27
- 2.0.0 — 2015-01-27
- 1.1.0 — 2015-01-26
- 1.0.1 — 2015-01-24
- 1.0.0 — 2015-01-24
- 0.0.19 — 2015-01-24
- 0.0.18 — 2014-04-12
- 0.0.17 — 2014-04-12
- 0.0.16 — 2014-04-11
- 0.0.15 — 2014-04-11
- 0.0.14 — 2014-04-10
- 0.0.13 — 2014-04-10
- 0.0.12 — 2014-03-11
- 0.0.11 — 2014-03-11
- 0.0.10 — 2014-03-11
- … 9 more at https://npm.io/package/hammerdown/versions

## README

hammerdown
==========

[![Build Status](https://travis-ci.org/tjchaplin/hammerdown.png?branch=master)](https://travis-ci.org/tjchaplin/hammerdown)

Streaming html to markdown writer

# Get Started

Checkout The Live Demo [here!](http://tjchaplin.github.io/hammerdown/)

## Simple Example

```javascript
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

```javascript
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:

```javascript
//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

```javascript
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](https://github.com/neocotic/html.md))
* Lack of support for github flavored markdown ([to-markdown](https://github.com/domchristie/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](https://help.github.com/articles/github-flavored-markdown) definitions.

Markdown is a mechanism to create documents. [See](http://daringfireball.net/projects/markdown/) 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](https://github.com/tjchaplin/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

```javascript
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**
```

```html
<!-- 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

```javascript
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|
```

```html
<!-- 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

```javascript
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;
//	};
//  ```
```

```html
<!-- 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

* Thanks to [karlcows Markdown Test Runner](https://github.com/karlcow/markdown-testsuite) I was able to provide a solid set of tests

* [to_markdown](https://github.com/domchristie/to-markdown) another good html to markdown tool by [domchristie](https://github.com/domchristie)

---
_Source: https://npm.io/package/hammerdown · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
