# hackmd-to-html-cli

> A node.js CLI tool for converting HackMD markdown to HTML.

Latest version **2.0.1** (published 2026-06-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install hackmd-to-html-cli
pnpm add hackmd-to-html-cli
yarn add hackmd-to-html-cli
bun add hackmd-to-html-cli
```

Provides the command `hmd2html`.

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2026-06-09 |
| First published | 2021-12-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 19 |
| Unpacked size | 7.5 MB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 25 |
| Author | Kashiwa |
| Maintainers | ksw2000 |
| Keywords | hackmd, markdown, html, cli, converter |

## Links

- npm: https://www.npmjs.com/package/hackmd-to-html-cli
- Repository: https://github.com/ksw2000/hackmd-to-html-cli
- Homepage: https://github.com/ksw2000/hackmd-to-html-cli.git
- Issues: https://github.com/ksw2000/hackmd-to-html-cli/issues
- npm.io page: https://npm.io/package/hackmd-to-html-cli

## Dependencies (19)

- [glob](https://npm.io/package/glob.md) ^11.0.0
- [yaml](https://npm.io/package/yaml.md) ^2.8.1
- [commander](https://npm.io/package/commander.md) ^14.0.1
- [papaparse](https://npm.io/package/papaparse.md) ^5.4.1
- [deflate-js](https://npm.io/package/deflate-js.md) ^0.2.3
- [markdown-it](https://npm.io/package/markdown-it.md) ^14.1.0
- [markdown-it-ins](https://npm.io/package/markdown-it-ins.md) ^4.0.0
- [markdown-it-sub](https://npm.io/package/markdown-it-sub.md) ^2.0.0
- [markdown-it-sup](https://npm.io/package/markdown-it-sup.md) ^2.0.0
- [markdown-it-abbr](https://npm.io/package/markdown-it-abbr.md) ^2.0.0
- [markdown-it-mark](https://npm.io/package/markdown-it-mark.md) ^4.0.0
- [markdown-it-ruby](https://npm.io/package/markdown-it-ruby.md) ^1.1.1
- [markdown-it-emoji](https://npm.io/package/markdown-it-emoji.md) ^3.0.0
- [markdown-it-anchor](https://npm.io/package/markdown-it-anchor.md) ^9.2.0
- [markdown-it-imsize](https://npm.io/package/markdown-it-imsize.md) ^2.0.1
- [markdown-it-deflist](https://npm.io/package/markdown-it-deflist.md) ^3.0.0
- [markdown-it-footnote](https://npm.io/package/markdown-it-footnote.md) ^4.0.0
- [markdown-it-mathjax3](https://npm.io/package/markdown-it-mathjax3.md) ^4.3.2
- [markdown-it-table-of-contents](https://npm.io/package/markdown-it-table-of-contents.md) ^1.1.0

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2026-06-09
- 2.0.0 — 2024-11-15
- 1.1.0 — 2024-01-25
- 1.0.0 — 2023-06-18
- 0.0.12 — 2023-05-13
- 0.0.11 — 2023-04-21
- 0.0.10 — 2023-04-03
- 0.0.9 — 2023-03-26
- 0.0.8 — 2023-02-25
- 0.0.7 — 2023-02-23
- 0.0.6 — 2023-02-01
- 0.0.5 — 2022-05-07
- 0.0.4 — 2021-12-16
- 0.0.3 — 2021-12-08
- 0.0.2 — 2021-12-06
- … 1 more at https://npm.io/package/hackmd-to-html-cli/versions

## README

# hackmd-to-html-cli

[![NPM version](https://img.shields.io/npm/v/hackmd-to-html-cli.svg?logo=npm&style=flat-square)](https://www.npmjs.org/package/hackmd-to-html-cli) ![](https://img.shields.io/github/license/ksw2000/hackmd-to-html-cli?color=yellow&style=flat-square) ![](https://img.shields.io/github/actions/workflow/status/ksw2000/hackmd-to-html-cli/gitpage.yml?branch=main&style=flat-square) ![](https://img.shields.io/npm/dt/hackmd-to-html-cli?color=blue&style=flat-square)

Not only is this a CLI tool, but it is also an importable package for converting standard Markdown and even [HackMD](https://hackmd.io/)-supported Markdown into HTML.

+ Example of input markdown: [./example/index.md](https://raw.githubusercontent.com/ksw2000/hackmd-to-html-cli/main/example/index.md)
+ Example of output html: [https://ksw2000.github.io/hackmd-to-html-cli/](https://ksw2000.github.io/hackmd-to-html-cli/)
+ Example of output html in dark mode: [https://ksw2000.github.io/hackmd-to-html-cli/index.dark.html](https://ksw2000.github.io/hackmd-to-html-cli/index.dark.html)
+ Example of converting in web: [https://ksw2000.github.io/hackmd-to-html-cli/webjs.html](https://ksw2000.github.io/hackmd-to-html-cli/webjs.html)

## Install

```sh
# CLI
npm install -g hackmd-to-html-cli

# Package
npm install hackmd-to-html-cli
```

## CLI

```sh
$ hmd2html --help
hmd2html --help
Usage: index [options]

Options:
  -v, --version                   output the current version
  -i, --input <files_or_urls...>  the path/url of input markdown files
  -d, --dest <dir>                the path of output directory (filename is generated automatically) (default: ./output)
  -o, --output <files...>         the path of output file (ignored if the flag -d is set) (default: "")
  -l, --layout <html_file>        specify the layout file (default: "")
  -b, --hardBreak                 use hard break instead of soft break
  -k, --dark                      use the dark mode layout (activate only if the -l option is not set)
  -h, --help                      display help for command
```

**Convert**

```sh
# convert files
$ hmd2html -i file1.md file2.md file3.md

# allow wildcard input
$ hmd2html -i dir/*.md

# allow url input
$ hmd2html -i https://github.com/ksw2000/hackmd-to-html-cli/blob/main/example/index.md

# set output folder
$ hmd2html -i file1.md -d ./my_output

# set the filename of output
$ hmd2html -i file1.md -o file1.html
$ hmd2html -i file1.md file2.md -o file1.html file2.html

# use default darkmode layout
$ hmd2html -i file1.md -k

# use custom layout
$ hmd2html -i hello.md -l ./myLayout.html
```

## Layouts

We provide the two default layouts. Please see layouts here: [https://github.com/ksw2000/hackmd-to-html-cli/blob/main/layouts/](./layouts/)

+ `{{main}}` renders main content of markdown.
+ `{{lang}}` renders lang property if there are yaml metadata about `lang` in markdown file. e.g. `lang="zh-TW"`
+ `{{dir}}` renders dir property if there are yaml metadata about `dir` in markdown file. e.g. `dir="ltr"`
+ `{{meta}}` renders meta tag if there are yaml metadata about `title`, `description`, `robots` or`image`. e.g. `<meta name="robots" content="noindex">`

Example:

```html
<!DOCTYPE html>
<html {{lang}} {{dir}}>
<head>
    {{metas}}
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <body>
      {{main}}
    </body>
</html>
```

There are some features rendered by other dependencies. Thus, in our default layout, we include those dependencies.

## Example

### CommonJS

```js
const { Converter } = require('hackmd-to-html-cli')

const converter = new Converter();
const res = converter.render("# hello");

console.log(res.main);
```


### ES Module

```ts
import { Converter } from "hackmd-to-html-cli"

const converter = new Converter();
const res = converter.render("# hello");

console.log(res.main);
```

### Web

```js
const converter = new window.hmd2html.Converter();
const res = converter.render("# hello");
console.log(res.main);
```

## Support

`hmd2html`: our tool (the latest)

`HackMD Default Converter`: The default markdown to html converter provided by HackMD, i.e., download HTML file on HackMD.

HackMD fully supports syntax: [features](https://hackmd.io/features-tw?both)

| Features   | hmd2html  | HackMD<br>Default Converter |
|---------------------------------|:--:|:--:|
| ToC                             | ✅ | ✅ |
| Emoji                           | ✅ | ✅ |
| ToDo list                       | ✅ | ✅ |
| Code block                      | ✅ | ✅ |
| - Show line number or not       | ✅ | ❌ |
| - Specify the start line number | ✅ | ❌ |
| - Continue line number          | ✅ | ❌ |
| Blockquote                      | ✅ | ✅ |
| - specify your name             | ✅ | ✅ |
| - specify time                  | ✅ | ✅ |
| - color                         | ✅ | ✅ |
| Render CSV as table             | ✅ | ✅ |
| MathJax                         | ✅ | ✅ |
| Sequence diagrams               | ✅ | ❌ |
| Flow charts                     | ✅ | ❌ |
| Graphviz                        | ✅ | ❌ |
| Mermaid                         | ✅ | ❌ |
| Abc                             | ✅ | ❌ |
| PlantUML                        | ✅ | ✅ |
| Vega-Lite                       | ✅ | ❌ |
| Fretboard                       | ✅ | ❌ |
| Alert Area                      | ✅ | ✅ |
| Detail                          | ✅ | ✅ |
| Spoiler container               | ✅ | ✅ |
| Headers h1-h6                   | ✅ | ✅ |
| Horizontal line `---` `***`     | ✅ | ✅ |
| Bold `**b**` `__b__`            | ✅ | ✅ |
| Italic `*i*` `_i_`              | ✅ | ✅ |
| Deleted text `~~del~~`          | ✅ | ✅ |
| Superscript `^sup^`             | ✅ | ✅ |
| Subscript  `~sub~`              | ✅ | ✅ |
| Inserted text `++ins++`         | ✅ | ✅ |
| Marked text `==mark==`          | ✅ | ✅ |
| Ruby case                       | ✅ | ✅ |
| Typographic<br>replacements     | ✅ | ✅ |
| Blockquotes                     | ✅ | ✅ |
| List                            | ✅ | ✅ |
| Tables                          | ✅ | ✅ |
| Links                           | ✅ | ✅ |
| Link with title                 | ✅ | ✅ |
| Autoconverted link              | ✅ | ✅ |
| Image                           | ✅ | ✅ |
| - normal                        | ✅ | ✅ |
| - with title                    | ✅ | ✅ |
| - given size                    | ✅ | ✅ |
| Footnotes                       | ✅ | ✅ |
| Definition list                 | ✅ | ✅ |
| Abbreviations                   | ✅ | ✅ |

### Support Externals

| Features    | hmd2html  | HackMD<br>Default Converter|
|-------------|:---------:|:---------:|
| Youtube     | ✅       | ✅        |
| Vimeo       | ✅       | ❌        |
| Gist        | ✅       | ✅        |
| SlideShare  | ❌       | ❌        |
| Speakerdeck | ✅       | ✅        |
| PDF         | ✅       | ✅        |
| Figma       | ✅       | ✅        |

### Support YAML Metadata

| Features      | hmd2html  | Implementation  |
|---------------|:---------:|:-------:|
| title         | ✅       | `<title></title>`<br>`<meta name="twitter:title">`<br>`<meta property="og:title">`|
| description   | ✅       | `<meta name="description">`<br>`<meta name="twitter:description">`<br>`<meta property="og:description">` |
| robots        | ✅       | `<meta name="robots">` |
| lang          | ✅       | `<html lang="">` |
| dir           | ✅       | `<html dir="">` |
| image         | ✅       | `<meta property="og:image">`<br>`<meta name="twitter:image:src">` |
| others        | ✅       | Hide the metadata by html comment |

HackMD sets the `lang` tag and `dir` tag at the beginning of `<body>`. hmd2html sets the the `lang` tag and `dir` tag at `<html>` when using default layout.

## Development

1. `npm run lint` to check the format of source code.
2. `npm run example` runs example for this package, which generates result from `./example` and places them in `./output`.
3. `npm test` runs unit test files whose filenames end with `.spec.ts`

## Contributing

Contributions to **hackmd-to-html-cli** are welcome and highly appreciated. Please run lint `npm run lint` and test `npm run test` before pull requesting.

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