Skip to content

ksw2000/hackmd-to-html-cli

Repository files navigation

hackmd-to-html-cli

NPM version

Not only is this a CLI tool, but it is also an importable package for converting standard Markdown and even HackMD-supported Markdown into HTML.

Install

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

# Package
npm install hackmd-to-html-cli

CLI

$ 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

# 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/

  • {{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 orimage. e.g. <meta name="robots" content="noindex">

Example:

<!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

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

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

console.log(res.main);

ES Module

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

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

console.log(res.main);

Web

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

Features hmd2html HackMD
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
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
Default Converter
Youtube βœ… βœ…
Vimeo βœ… ❌
Gist βœ… βœ…
SlideShare ❌ ❌
Speakerdeck βœ… βœ…
PDF βœ… βœ…
Figma βœ… βœ…

Support YAML Metadata

Features hmd2html Implementation
title βœ… <title></title>
<meta name="twitter:title">
<meta property="og:title">
description βœ… <meta name="description">
<meta name="twitter:description">
<meta property="og:description">
robots βœ… <meta name="robots">
lang βœ… <html lang="">
dir βœ… <html dir="">
image βœ… <meta property="og:image">
<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.

About

A CLI/Package converts HackMD markdown to HTML.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •