Skip to content

dingZvel/md2html

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

md2html

md2html logo

A small, polished command-line tool that converts Markdown files into standalone HTML pages.

md2html supports common Markdown syntax, watches files for changes, highlights code with Light+ and Dark+ themes, and produces a complete HTML document with no external runtime assets.

Demo

Light and dark HTML output generated by md2html

Generated pages include syntax highlighting, line numbers, line hover states, one-click code copying, and a persistent light/dark theme switcher.

Features

  • Headings, paragraphs, ordered and unordered lists
  • Links, images, blockquotes, tables, and fenced code blocks
  • Syntax highlighting for code blocks and inline code
  • Light+ and Dark+ themes that follow the system preference by default
  • A theme switcher that remembers the reader's choice
  • Code language labels, line numbers, line hover highlighting, and copy buttons
  • A built-in responsive stylesheet with no external CSS or JavaScript files
  • Watch mode for automatic conversion during editing
  • Helpful CLI validation and error messages

Requirements

  • Node.js 18 or newer
  • npm

Check your Node.js version with:

node --version

Installation

Clone the repository and enter the project directory:

git clone https://github.com/dingZvel/md2html.git
cd md2html

Install the dependencies and compile the TypeScript source:

npm install
npm run build

You can now run the compiled CLI directly:

node dist/index.js input.md

To make the md2html command available globally from this source checkout, create an npm link:

npm link

After linking, the command can be used from any directory:

md2html input.md

To remove the global link later:

npm unlink --global md2html-cli

Usage

Usage: md2html <input.md> [-o output.html] [--watch]

Options:
  -o, --output <file>  Specify the output HTML file
  -w, --watch          Watch for changes and convert automatically
  -h, --help           Show help
  -v, --version        Show version

Convert a file

md2html notes.md

When no output is specified, the HTML file is written next to the input file using the same base name:

notes.md  ->  notes.html

Choose an output file

md2html notes.md -o public/index.html

The long option works as well:

md2html notes.md --output public/index.html

Watch for changes

md2html notes.md --watch

The first conversion runs immediately. Each time notes.md changes, the output file is generated again. Press Ctrl+C to stop watching.

Watch mode can be combined with a custom output path:

md2html notes.md -o public/index.html --watch

Run without a global link

Use the development command to execute the TypeScript source directly:

npm run dev -- sample.md -o sample.html

Or run the compiled file after npm run build:

node dist/index.js sample.md -o sample.html

Markdown example

# Project Notes

This paragraph contains a [link](https://example.com) and `inline code`.

- First item
- Second item

```typescript
const greeting: string = "Hello, Markdown!";
console.log(greeting);
```

![Example image](https://example.com/image.png)

Convert the bundled example and open the result in a browser:

md2html sample.md -o sample.html

See sample.md for a broader syntax example.

Generated HTML

Each output file is standalone and contains:

  • Semantic HTML generated from the Markdown source
  • Embedded responsive page styles
  • Embedded Light+ and Dark+ syntax colors
  • Embedded theme-switching and code-copy behavior
  • A page title based on the input filename

The generated page does not need this package or a web server to render. It can be opened directly from the filesystem.

Development

# Run the TypeScript source
npm run dev -- sample.md

# Compile to dist/
npm run build

# Check TypeScript types without emitting files
npm run typecheck

# Run the compiled CLI
npm start -- sample.md

Project structure:

.
├── assets/          README images
├── dist/            compiled JavaScript
├── src/index.ts     CLI and HTML renderer
├── sample.md        example Markdown document
├── package.json
└── tsconfig.json

License

MIT

Disclaimer

This tool was vibe coded using Codex with GPT-5.6-sol.

About

A polished TypeScript CLI that converts Markdown to styled HTML with syntax highlighting, themes, code copying, and watch mode.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages