A CLI tool that converts Markdown into template-based HTML.
Most Markdown tools stop at “Markdown → HTML”.
md-xformer goes one step further:
it lets you replace Markdown elements (headings, code blocks, etc.) with your own HTML templates.
This tool is designed for cases where HTML structure and styling must be strictly controlled, such as internal blogs or CMS-driven sites.
Warning
This is a work-in-progress project. Use at your own risk.
- Convert Markdown to HTML
- Replace Markdown elements using HTML templates
- Syntax highlighting via
highlight.js - Output HTML ready to paste into:
- WordPress
- Internal CMS
- Static sites
md-xformer is a good fit if:
- You want to write in Markdown but enforce a fixed HTML structure
- Your organization has strict design or markup rules
- You need build-time HTML output
It is not a good fit if:
- You want live Markdown rendering in the browser
- You need MDX / React integration
- You want a full static site generator
npm install -g md-xformerOr run without installing:
npx md-xformer --helpThe fastest way to get started is with the init command, which scaffolds a complete project structure:
md-xformer initThis creates:
.md-xformer/
templates/
h2.template.html
h3.template.html
p.template.html
codeblock.template.html
articles/
sample.mdThen run the transformer:
md-xformer articles -t .md-xformer/templates -o distYour transformed HTML will be in dist/articles/sample.html.
md-xformer init [--preset <name>] [--dir <path>] [--force] [--dry-run]--preset <name>— Choose scaffold preset:example(default): Standard templates for common elementsgeneric: Minimal template set
--dir <path>— Target directory (defaults to current directory)--force— Overwrite existing files--dry-run— Preview what would be created without writing files
Examples:
# Initialize with example preset (default)
md-xformer init
# Initialize with minimal generic preset
md-xformer init --preset generic
# Preview what would be created
md-xformer init --dry-run
# Initialize in a specific directory
md-xformer init --dir my-project
# Overwrite existing files
md-xformer init --forcemd-xformer <input> -o <outDir> [-t <templateDir>] [--ext html] [--clean] [--dry-run] [--verbose] [--allow-html]md-xformer articles \
-t template \
-o distarticles— Markdown file or directorytemplate— Directory containing HTML templates (must exist)dist— Output directory
Templates are matched to Markdown elements by filename.
template/
├── h1.template.html
├── h2.template.html
├── h3.template.html
├── codeblock.template.html
└── p.template.htmlTip: Run
md-xformer initto generate a starter set of templates automatically.
After running md-xformer init, you can customize templates in .md-xformer/templates/:
- Edit any
.template.htmlfile to change the HTML structure - Add new template files for other elements (e.g.,
h4.template.html,blockquote.template.html)
<h2 id="{{ id }}">{{ h2 }}</h2>Template variables for headings:
{{ h1 }},{{ h2 }},{{ h3 }}, etc. — Inner text or HTML for each heading level{{ id }}— Slugified heading ID
Template variables for other elements:
{{ p }}— Inner text or HTML for paragraphs
You can customize the HTML wrapper for fenced code blocks:
<pre class="code-block">
<div class="code-block__meta">
<span class="code-block__lang">{{ lang }}</span>
</div>
<code class="hljs language-{{ lang }}">{{{ code }}}</code>
</pre>Available variables:
{{ lang }}— Language name (e.g.,typescript,python, ortextif not specified){{{ code }}}— Highlighted HTML from highlight.js (raw HTML, use triple braces){{ raw }}— Original code as escaped text (safe for display)
Important: Use triple braces {{{ code }}} to inject the highlighted HTML without escaping. Regular double braces {{ }} will escape HTML entities.
If no codeblock.template.html is provided, the default wrapper is used:
<pre><code class="hljs language-{lang}">...</code></pre>- Powered by
highlight.js - Language-specified code blocks are highlighted automatically
- Unsupported or unspecified languages are safely escaped
```ts
const x: number = 1;
```- Use
markdown-itdirectly - No magic, no hidden conventions
- CLI + templates only
- CMS-agnostic (WordPress support is handled via templates)