Render Pug as HTML
Indentation-aware Pug parser that emits clean, semantic HTML. ID and class shorthand expand to attributes, parenthesised attribute lists become space-separated key/value pairs.
<div class="card">
<h1 id="title">Hello</h1>
<p>Some text</p>
<a href="https://example.com" target="_blank">Visit</a>
<ul>
<li>First</li>
<li>Second</li>
</ul>
</div>How rendering works
Each non-blank line becomes one element. Indentation expresses nesting, the tag-id-class shorthand maps directly to attributes, and explicit (key=\"value\", …) lists round out anything the shorthand can't express.
- 01
Paste Pug
Lines starting with | are plain text appended to the parent element.
Parsing is strict-but-tolerant — comments and trailing commas are accepted on input where the source format historically permits them; output stays canonical.
inputstricttolerantliveparsein · sourcepug · livediv.card h1 Hello
loaded · parsedtarget · ready - 02
Shorthand expanded
#hi becomes id="hi"; .card.hero becomes class="card hero".
Conversion preserves type information where the target supports it (numbers stay numeric, booleans stay boolean) so the destination parser never has to re-coerce.
shorthandtype-preservinglosslesslivememoised#. · optionsattrs · live<div id="hi" class="card hero">
options applied · liveround-trip - 03
Attributes parsed
Parenthesised key=value pairs become attribute strings on the opening tag.
Re-encoding is idempotent: running output back through the same converter produces the same bytes, which keeps round-trips git-friendly.
attrsidempotentround-tripdiff-cleandeterministic() · convertedtag · readya(href="...") → <a href="...">
converted · livediff-clean - 04
Copy or download
Save as .html — paste into a static site, an Express render or a documentation page.
Copy writes via
navigator.clipboard.writeText; downloads use the target’s native MIME so editors apply the right syntax highlighting on open.exportclipboardtarget MIMEblobclient-side✓ · copiedready · done✓ Copied
shipped · ready to shipsuccess
Converting between formats, safely
Pick the strictest source format
Lossy formats hide bugs. Choose JSON or YAML as your source-of-truth, convert downstream as needed.
Round-trip in CI
If your converter is idempotent, your CI can verify A → B → A equals the original. Catches subtle data loss.
Numbers vs strings differ
YAML/TOML have a number type; CSV doesn’t. Quote IDs in CSV to keep leading-zero values intact.
Watch character encoding
Source format may be Latin-1 / Windows-1252; target should be UTF-8. Convert encoding before structure.
Preserve comments where you can
YAML and TOML support comments. Don’t silently drop them — they often encode intent.
Schema-aware beats blind
Use a schema to guide conversion. Field types, required-ness, and defaults survive better with structure.
When to render Pug
Express, static sites, prototypes.
Express previews
Render a snippet to HTML without booting Express. Type information survives: numbers stay numeric, booleans stay boolean, strings stay strings. The destination parser doesn't have to re-coerce, which avoids the "'true' becomes "true"" bug class.
round-trip safeStatic-site builds
Snapshot a Pug page for a CDN drop or sanity check. Run output back through the inverse converter to verify idempotent round-trips in CI. A → B → A should produce byte-identical input — if it doesn't, you've found data loss.
type-preservingDesigner hand-off
Show non-Pug stakeholders what the markup will look like. Comments and metadata survive where the target format supports them (YAML, TOML, HCL). The tool doesn't silently drop intent-encoded annotations, which keeps your config self-documenting.
schema-awareDocumentation
Embed runnable Pug examples and their HTML side by side. Pair with a schema (JSON Schema, OpenAPI, Zod, Pydantic) to catch shape drift on either side. Catch breaking changes at conversion time rather than at runtime in production.
losslessMigrations
Lift Pug pages out of an Express app into a static site. Output respects target-format conventions: quoting in CSV, indent in YAML, brackets in JSON. Existing parsers don't need patches, and the result drops into legacy pipelines unchanged.
diff-cleanTeaching
Demonstrate how indentation maps to HTML nesting. Encoding-aware: handles UTF-8 vs UTF-16 vs Latin-1 / Windows-1252 transparently. The character-set surprise that breaks "works on my machine" doesn't apply here.
spec-gradeFrequently asked questions
Something missing?
Tell us what you need. We ship the top requests every two weeks.