Opinionated general formatter for your Angular, Vue, Svelte or pure HTML5 templates. Try it on the playground.
Project status: Unfortunately, This project lacks maintainers. Prettier has landed HTML support in 1.15.0. I recommend it to use it if it matches your requirements. If you want to contribute to this project, feel free to create a PR/Issue.
Adding this flag before a tag will preserve from whitespace and/or attribute wrapping.
<!--prettyhtml-ignore--> <div></div>
<!--prettyhtml-preserve-whitespace--> <h1> foo </h1>
<!--prettyhtml-preserve-attribute-wrapping--> <h1 foo="bar" ...> foo </h1>
# regular $ npm install @starptech/prettyhtml --global # when using proxy like sinopia/verdaccio $ npm install @starptech/prettyhtml --global --registry=https://registry.npmjs.org/
This will process recursively all HTML files in the current directory.
$ prettyhtml example.html "./**/*.html"
Pre-Commit hook integration
We provide a simple package called prettyhtml-quick which is able to format only changed files. This example use husky to manage git hooks in the package.json
{ "husky": { "hooks": { "precommit": "prettyhtml-quick --staged" } } }
prettyhtml(doc: string, options?): vFile
Formats a string and returns a vFile
. The method can throw e.g when a parsing error was produced. The error is from type vfile-message
.
The space width of your indentation level (default: 2)
Use tabs instead spaces for indentation (default: false)
Use different maximum line length (default: 80)
Use prettier for embedded content (default: true)
Use custom prettier settings for embedded content (default: local config)
Use single quote instead double quotes (default: false)
Force to wrap attributes (when it has multiple, default: false)
Sort attributes alphabetically (default: false)
Prettier has landed HTML support some days ago. This is awesome and will help many people to reduce the headache of correct formatting in teams. The reason why I still using prettyhtml is clear:
Big thanks to the creators of the excellent rehype and unified ecosystem.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4