m2h is a simple command-line tool that converts Markdown to HTML with syntax
highlighting for code blocks. It allows you to customize the styling by applying
different themes at render time.
cargo install m2h --lockedBy default, m2h reads Markdown from standard input and outputs HTML.
$ echo "# Hello, world!" | m2h<h1>Hello, world!</h1>Code blocks in the Markdown input are annotated with CSS classes rather than inline styles. This allows themes to be applied dynamically at render time.
$ echo $'```rust
fn main() {
println!("Hello, world!");
}```' | m2h<pre><code class="language-rust"><span class="source rust"><span class="meta
function rust"><span class="meta function rust"><span class="storage type
function rust">fn ...You can then apply a theme by supplying CSS that styles these class names.
To list all available themes, run:
m2h themeTo retrieve the CSS for a specific theme, run:
m2h theme <THEME_NAME>For example:
m2h theme MonokaiThis will output the corresponding CSS, which you can include in your HTML.
-
Convert Markdown to HTML:
cat example.md | m2h > output.html
-
Retrieve the CSS for a theme:
m2h theme Solarized-Dark > theme.css -
Include
theme.cssin your webpage to style the syntax highlighting dynamically.
- pulldown-cmark - Markdown parsing
- syntect - Syntax highlighting
MIT License