Skip to content

utility to transform hast (HTML) to mdast (markdown)

License

Notifications You must be signed in to change notification settings

syntax-tree/hast-util-to-mdast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hast-util-to-mdast

Convert HAST trees to MDAST trees.

About

Based on the code in mdast-util-to-hast, this module provides a way to transform an HTML abstract syntax tree into a markdown abstract syntax tree.

Used with rehype and remark, this allows you to convert HTML into markdown.

Work in progress

So far this only transforms a few HTML elements, and there's more work to do. To see what's been completed so far look at the handlers directory.

Install

npm install --save hast-util-to-mdast

Usage

var unified = require('unified')
var parse = require('rehype-parse')
var stringify = require('remark-stringify')

var toMDAST = require('hast-util-to-mdast')

var result = unified()
  .use(parse)
  .use(function () { return toMDAST })
  .use(stringify)
  .process(html, { fragment: true })

console.log(result.contents)

License

MIT