#markdown-html #syntax-highlighting #html #markdown #cli

app m2h

Convert Markdown to HTML with syntax highlighting

1 unstable release

new 0.1.0 Feb 6, 2025

#244 in Text processing

Download history 119/week @ 2025-02-03

119 downloads per month

MIT license

11KB
135 lines

m2h

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.

Install

cargo install m2h --locked

Usage

Convert Markdown to HTML

By default, m2h reads Markdown from standard input and outputs HTML.

$ echo "# Hello, world!" | m2h
<h1>Hello, world!</h1>

Syntax Highlighting

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.

Example

$ echo $'```rust
fn main() {
    println!("Hello, world!");
}```' | m2h

Output

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

List Available Themes

To list all available themes, run:

m2h theme

Get Theme CSS

To retrieve the CSS for a specific theme, run:

m2h theme <THEME_NAME>

For example:

m2h theme Monokai

This will output the corresponding CSS, which you can include in your HTML.

Example: Convert and Apply a Theme

  1. Convert Markdown to HTML:

    cat example.md | m2h > output.html
    
  2. Retrieve the CSS for a theme:

    m2h theme Solarized-Dark > theme.css
    
  3. Include theme.css in your webpage to style the syntax highlighting dynamically.

Built With 🙏

License

MIT License

Dependencies

~11–20MB
~246K SLoC