explaingit

patrickarlt/hast-util-to-mdast

Analysis updated 2026-07-15 · repo last pushed 2019-08-24

JavaScriptAudience · developerComplexity · 2/5DormantSetup · moderate

TLDR

A JavaScript library that converts HTML content into clean Markdown text. It maps HTML tags like headings and bold tags to their Markdown equivalents, and lets you write custom rules for tags that Markdown does not support.

Mindmap

mindmap
  root((repo))
    What it does
      Converts HTML to Markdown
      Maps tags to Markdown
      Handles unsupported tags
    Tech stack
      JavaScript
      Node.js
      unified ecosystem
    Use cases
      Migrate web content
      Save pasted HTML as Markdown
      Build content pipelines
    Audience
      Developers
      Content migration tools
    Notable
      Use rehype-remark wrapper
      Sanitize untrusted HTML
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Build an automated tool that migrates old web pages into Markdown for a modern documentation platform.

USE CASE 2

Create a system that accepts rich text pasted from a word processor and saves it as clean Markdown.

USE CASE 3

Convert HTML content into a readme file or wiki page while keeping it human-readable.

USE CASE 4

Write custom rules to pass unsupported HTML tags like SVG straight through into the Markdown output.

What is it built with?

JavaScriptNode.jsunifiedhastmdast

How does it compare?

patrickarlt/hast-util-to-mdastaj-michael/tetrisalce/yogajs
LanguageJavaScriptJavaScriptJavaScript
Last pushed2019-08-242015-04-082017-11-07
MaintenanceDormantDormantDormant
Setup difficultymoderatemoderatehard
Complexity2/52/51/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 30min

Works within the unified ecosystem so you need to understand hast and mdast tree structures, and most users will want the rehype-remark wrapper for easier setup.

The license is not mentioned in the explanation, so it is unclear what permissions you have. Check the repository for license details before using it.

In plain English

The hast-util-to-mdast library converts HTML content into Markdown. This is handy when you have web pages or rich text formatted in HTML and need to translate it into clean, readable Markdown for documentation, a readme file, or a wiki. Under the hood, this tool takes a structural map of an HTML document and translates it into the equivalent structure for Markdown. For example, it knows that an HTML <h2> heading tag should become ## in Markdown, and that a <strong> bold tag should become **. It automatically handles paragraph spacing and tries to keep the final text as human-readable as possible. You would use this if you are building an automated tool that migrates old web content into a modern writing platform, or if you are building a system that accepts HTML pasted from a word processor but needs to save it as Markdown. The developers note that most people will actually want to use a companion tool called rehype-remark to do this job, which uses this library behind the scenes but is easier to plug into a broader content pipeline. One notable feature is that it does not just give up when it encounters HTML tags that do not exist in Markdown, like an SVG graphic. By default it drops content it cannot translate, but it gives you a way to write custom rules to pass that raw HTML straight through into the Markdown file so you do not lose your content. The developers also include a warning that if you are working with untrusted HTML, you should clean it first. If the HTML contains malicious scripts, converting it could pass that danger along into your final document.

Copy-paste prompts

Prompt 1
I have HTML content from old web pages that I need to convert to Markdown using hast-util-to-mdast. Show me how to set up the conversion and map headings, bold tags, and paragraphs correctly.
Prompt 2
I am using hast-util-to-mdast and some HTML tags like SVG do not have a Markdown equivalent. How do I write a custom rule to pass that raw HTML through into the Markdown output instead of dropping it?
Prompt 3
I want to convert HTML to Markdown in my content pipeline. Should I use hast-util-to-mdast directly or the rehype-remark wrapper? Show me the simpler approach with rehype-remark and explain how this library fits in.
Prompt 4
I am building a tool that accepts HTML pasted by users and converts it to Markdown with hast-util-to-mdast. How do I sanitize the untrusted HTML first to remove any malicious scripts before conversion?

Frequently asked questions

What is hast-util-to-mdast?

A JavaScript library that converts HTML content into clean Markdown text. It maps HTML tags like headings and bold tags to their Markdown equivalents, and lets you write custom rules for tags that Markdown does not support.

What language is hast-util-to-mdast written in?

Mainly JavaScript. The stack also includes JavaScript, Node.js, unified.

Is hast-util-to-mdast actively maintained?

Dormant — no commits in 2+ years (last push 2019-08-24).

What license does hast-util-to-mdast use?

The license is not mentioned in the explanation, so it is unclear what permissions you have. Check the repository for license details before using it.

How hard is hast-util-to-mdast to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is hast-util-to-mdast for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.