npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hammerdown

v2.0.1

Published

Streaming HTML To Markdown Writer

Downloads

476

Readme

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