Skip to content

Repository files navigation

md-html-cli

md-html-cli

GitHub Repo starsGitHub forksGitHub watchersGitHub contributorsGitHub last commitGitHub licenseGitHub closed issuesGitHub closed pull requests

CLI tool for converting markdown to a single html file.
🇨🇳 中文 | 🇺🇸 English

Installation

Install Go language 1.17 or above, and then execute the following command:

go install github.com/GoAid/md-html-cli@latest

Usage

go run github.com/GoAid/md-html-cli@latest /?
Usage:
go run github.com/GoAid/md-html-cli@latest [OPTIONS]
Application Options:
/i, /input: input Markdown
/o, /output: output HTML
/r, /replace: replace content key-value pairs
/l, /lang: html lang attribute value, default is en
/t, /title: custom html title, default is output file name
/f, /favicon: favicon image path, if embed is used, will embed by base64 encoding
/e, /embed embed image by base64 encoding
/center whether to center the image
/m, /mathjax use MathJax
/s, /span enable table row/col span
/b, /border: add a border style of a specified color to image labels, e.g. gray, #eee, rgb(0,0,0)
/c, /css: custom css file path
/theme:[vue|side] output HTML theme
/toc generate TOC
/level:[1|2|3|4|5] The heading level when generating TOC (default: 3)
/g, /gen use HTML comments to record generation time
Help Options:
/? Show this help message
/h, /help Show this help message

Sample

GitHub Pages

The html file is generated by following command

md-html-cli -i "example/*.md" -o gh-pages/index.html -l en -t "Example Page" -f example/img/go.png -ems -c example/css/custom-css.css --theme vue --toc --gen

Example

Preview
MarkdownHTML
mh-highlight-md.pngmh-highlight-html.png
mh-image-md.pngmh-image-html.png
mh-image-size-md.pngmh-image-size-html.png
mh-link-md.pngmh-link-html.png
mh-mathjax-md.pngmh-mathjax-html.png
mh-table-span-md.pngmh-table-span-html.png
mh-table-without-header-md.pngmh-table-without-header-html.png
mh-task-list-md.pngmh-task-list-html.png

Development

theme template

Create a folder for storing theme template files in the theme folder, and create a .gohtml type template file with the same name in the folder.

template variable

VariableDescription
{{ .HTMLLang }}HTML language attribute values, such as en, zh, etc.
{{ .HTMLTitle }}HTML custom title, the default is the output file name.
{{ if .Favicon }}{{ end }}Whether to add favicon.ico
{{ .FaviconHref }}favicon.ico tag element
{{ if .TOC }}{{ end }}Whether to generate a table of content
{{ if .CSS }}{{ end }}Whether to add a custom style
{{ .ConvertedCSS }}Customize style tag and content
{{ if .MathJax }}{{ end }}Whether to use MathJax to render mathematical formulas
{{ .MathJaxConfig }}MathJax profile JS tag element
{{ .MathJaxTeXSVG }}MathJax rendering tool JS tag element
{{ .ConvertedHTML }}The converted HTML main content
{{ .GeneratedAt }}HTML comments to record generation time

template function

FunctionDescription
{{ "<!-- HTML tag -->" | safeHTML }}safeHTML is used to retain HTML comments
{{ "/* CSS content */" | safeCSS }}safeCSS is used to retain CSS comments
{{ "/* JS content */" | safeJS }}safeJS is used to retain JS comments

Acknowledgement

About

🔁 CLI tool for converting markdown to a single html file. 用于将 markdown 转换为单个 html 文件的 CLI 实用工具。

Topics

Resources

Stars

11 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages