• Stars
    star
    271
  • Rank 151,717 (Top 3 %)
  • Language
    HTML
  • Created almost 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tool for converting HTML to Markdown, like html2markdown.

h2m

logo

npm Build Status Coverage Status

Tool for converting HTML to Markdown, like html2markdown.

online converter: http://island205.github.io/h2m/

online converter

Install

$npm install h2m

How to use

h2m(html[, options])

example

var h2m = require('h2m')

var md = h2m('<h1>Hello World</h1>')
// md = '# Hello World'

options

  • converter: the converter you can choose. now support CommonMark(default) and MarkdownExtra
  • overides: custom converter behavior:
h2m('<a href="http://island205.github.io/h2m/">h2m</a>', {
    overides: {
        a: function(node) {
          /**
          node is an object as the a tag:
          {
            name: "a",
            attrs: {
              href: 'http://island205.github.io/h2m/'
            },
            md: 'h2m'
          }
          */
          return `[This is an link element](${node.attrs.href})`
        }
    }
}

// output [This is an link element](http://island205.github.io/h2m/)

Command Line Tool

install

$ npm install h2m -g

h2m downloads

usage

$h2m -h

Usage: h2m [options]

Options:

  -V, --version      output the version number
  -f, --file <file>  HTML file path or an url adress (default: )
  -c, --clipboard    read HTML from clipboard
  -h, --help         output usage information

Convert a local file:

$ h2m  -f index.html

converting HTML to Markdown

made by [@island205](https://github.com/island205)

Can't be convert? welcome to submit an [issue](https://github.com/island205/h2m/issues/new).

Convert an online url:

$ h2m -f https://baidu.com

Convert from clipboard:

$ h2m -c

Save result:

$ h2m  -f https://google.com > google.md

Support

h2m supports standard Markdown sytax: CommonMark now and Markdown Extra.

CommonMark

  • br
  • em
  • strong
  • code
  • a
  • img
  • hr
  • ul, ol
  • pre
  • div
  • p
  • blockquote
  • h1 ~ h6

Markdown Extra

  • Special Attributes for headers link and image
  • Fenced Code Blocks
  • dl, dt, dd Definition Lists
  • abbr Abbreviations
  • table (tks @天凉's PR')

Contribution

PRs are welcome to implement other extend Markdown language, like Markdown Extra, GFM and so on.

More Repositories

1

Single-Page-App-Break

单页应用开发权威指南
590
star
2

HelloSea.js

专注Sea.js,深入浅出分析Sea.js模块机制
JavaScript
481
star
3

technode-tutorial

Tutorial on building chat app with node.js, socket.io and angular.js.
JavaScript
309
star
4

Lu-Hire

陆金所大前端招聘!
HTML
61
star
5

browserify-loader

A CommonJS Loader for browserify workflow.
JavaScript
45
star
6

H5Compass

HTML5 Compass for Web.
JavaScript
34
star
7

island205.github.com

My Heart For You
HTML
31
star
8

The-Little-Book-on-Promise

Promise 小书
27
star
9

f5

a node static server which can refrash after modify
CoffeeScript
19
star
10

bodule

module solution for browser
JavaScript
17
star
11

music163

Mac App build on MacGap
Objective-C
13
star
12

DoctorJS

线上JS报错监控系统。
Ruby
12
star
13

Slides

我的分享收集
8
star
14

ReactUnitTesting

JavaScript
7
star
15

BarnJS

IndexedDB Wrapper
JavaScript
6
star
16

backbone.tinywing

A template engine for backbone.
CoffeeScript
5
star
17

f2e-style-guide

styleguide for us
JavaScript
5
star
18

Venus

A canvas wrapper like jQuery to DOM
JavaScript
5
star
19

Thunder

JavaScript
3
star
20

bodule-engine

A bodule module runtime, maybe with a loader.
JavaScript
3
star
21

Coffee

CoffeeScript Editor for chrome extension
JavaScript
2
star
22

basestone

smart data structure
JavaScript
2
star
23

pixelegos

An mobile web App for drawing with PIXEL
JavaScript
1
star
24

noloader

node no loader
JavaScript
1
star
25

todomvc-in-bl

rewrite todomvc with browserify-loader
JavaScript
1
star
26

zhihu.md

transfer zhuanlan.zhihu.com artcle to md
JavaScript
1
star
27

CPU-Watcher

基于D2上QQ空间前端的介绍,实现一个能真实反映CPU消耗的监控器。
JavaScript
1
star
28

spring.js

TypeScript
1
star
29

ngDribbble

Dribbble App on Ionic
JavaScript
1
star