Skip to content

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

License

Notifications You must be signed in to change notification settings

GoAid/md-html-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

md-html-cli

md-html-cli

GitHub Repo stars GitHub forks GitHub watchers GitHub contributors GitHub last commit GitHub license GitHub closed issues GitHub 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
Markdown HTML
mh-highlight-md.png mh-highlight-html.png
mh-image-md.png mh-image-html.png
mh-image-size-md.png mh-image-size-html.png
mh-link-md.png mh-link-html.png
mh-mathjax-md.png mh-mathjax-html.png
mh-table-span-md.png mh-table-span-html.png
mh-table-without-header-md.png mh-table-without-header-html.png
mh-task-list-md.png mh-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

Variable Description
{{ .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

Function Description
{{ "<!-- 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

License

Stars

Watchers

Forks