Registry / devops / html-prettify

html-prettify

JSON →
library1.0.7jsnpmunverified

A simple, lightweight HTML prettifier with TypeScript definitions. Version 1.0.7 is the latest stable release. It takes HTML markup and indents it based on configurable character and count options. Differentiators: minimalistic, no dependencies, provides Vue-style template support (v-for, v-html). Alternative to more complex formatters like prettier.

npm install html-prettify
INSTALL
IMPORT
SIG · HTML-PRETTIFY
H
html-prettify
devopsjavascriptv1.0.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import prettify from 'html-prettify'
const prettify = require('html-prettify')
Package is ESM-only; use default import. CommonJS require will fail.
prettify
import { prettify } from 'html-prettify'
const { prettify } = require('html-prettify')
Named export also available. CommonJS destructuring fails.
prettify function
import pt from 'html-prettify'; pt(html, { char: 'tab', count: 4 })
Options object with 'char' (space or tab) and 'count' (number) to control indentation.

Demonstrates importing the default function and formatting a simple HTML string with space indentation.

import prettify from 'html-prettify'; const html = '<div><p>Hello</p></div>'; const result = prettify(html, { char: 'space', count: 2 }); console.log(result); // '<div>\n <p>Hello</p>\n</div>'
Debug
Known issues
breakingVersion 1.0.0 dropped CommonJS support; package is ESM-only.
fix
Use import instead of require(). If you must use CommonJS, consider dynamic import() or use an older version (<=0.0.x).
affects: >=1.0.0
gotchaThe 'char' option expects 'space' or 'tab' literally; other values may cause unexpected behavior or fallback to default.
fix
Always use exactly 'space' or 'tab' for the char option.
affects: >=1.0.0
gotchaVue directives like v-for with spaces may not be preserved exactly; some formatting removes extra whitespace inside attributes.
fix
Check output if you rely on specific attribute spacing; consider using a Vue-specific formatter if needed.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module
Using CommonJS require() with an ESM-only package.
fix
Use import or set type: 'module' in package.json if using Node.js, or use dynamic import().
TypeError: prettify is not a function
Importing named export as default incorrectly, or using wrong import syntax.
fix
Use default import: import prettify from 'html-prettify'.
Upgrade
Version history
1.0.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
html-prettify — npm install html-prettify · libregistry