All Projects → Prettyhtml → Prettyhtml

Prettyhtml / Prettyhtml

Licence: mit
💅 The formatter for the modern web https://prettyhtml.netlify.com/

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Prettyhtml

Prettier Atom
An atom package for the prettier formatter.
Stars: ✭ 750 (+211.2%)
Mutual labels:  prettier, formatter
Minna Ui
😸 A fast, friendly, and fun web UI kit for everyone.
Stars: ✭ 86 (-64.32%)
Mutual labels:  web-components, svelte
Svelte Flat
Flat UI components built with Svelte.
Stars: ✭ 13 (-94.61%)
Mutual labels:  web-components, svelte
Prettier Eslint
Code ➡️ prettier ➡️ eslint --fix ➡️ Formatted Code ✨
Stars: ✭ 3,435 (+1325.31%)
Mutual labels:  prettier, formatter
Prettier Plugin Apex
Code formatter for the Apex Programming Language
Stars: ✭ 138 (-42.74%)
Mutual labels:  prettier, formatter
Prettier Eslint Cli
CLI for prettier-eslint
Stars: ✭ 451 (+87.14%)
Mutual labels:  prettier, formatter
Parallel Prettier
Concurrent prettier runner
Stars: ✭ 84 (-65.15%)
Mutual labels:  prettier, formatter
prettier-check
Check that all files match prettier code style.
Stars: ✭ 54 (-77.59%)
Mutual labels:  formatter, prettier
Vime
Customizable, extensible, accessible and framework agnostic media player. Modern alternative to Video.js and Plyr. Supports HTML5, HLS, Dash, YouTube, Vimeo, Dailymotion...
Stars: ✭ 1,928 (+700%)
Mutual labels:  web-components, svelte
Javascriptprettier
A Visual Studio extension
Stars: ✭ 118 (-51.04%)
Mutual labels:  prettier, formatter
SENT-template
Skip setup and start code with SENT (Sapper Express Node Template) and other tools
Stars: ✭ 69 (-71.37%)
Mutual labels:  prettier, svelte
Spotless
Keep your code spotless
Stars: ✭ 2,285 (+848.13%)
Mutual labels:  prettier, formatter
svelte-webcomponents
A ready-to-use project template to build custom elements (web components) with Svelte 3 with support and examples for web components, jest, sass, nested components with props, eslinting, stylelinting, Github actions, propagating custom events from shadow-DOM to real-DOM etc.
Stars: ✭ 22 (-90.87%)
Mutual labels:  web-components, svelte
Prettier Plugin Csharp
Prettier C# Plugin
Stars: ✭ 224 (-7.05%)
Mutual labels:  prettier, formatter
prettier-eslint-atom
DEPRECATED IN FAVOR OF prettier-atom + ESLint integration
Stars: ✭ 64 (-73.44%)
Mutual labels:  formatter, prettier
Plugin Php
Prettier PHP Plugin
Stars: ✭ 1,243 (+415.77%)
Mutual labels:  prettier, formatter
pre-commit-hooks
Standardizing our code quality tooling 🛠️
Stars: ✭ 44 (-81.74%)
Mutual labels:  formatter, prettier
csharpier
CSharpier is an opinionated code formatter for c#.
Stars: ✭ 337 (+39.83%)
Mutual labels:  formatter, prettier
Prettier
Prettier is an opinionated code formatter.
Stars: ✭ 41,411 (+17082.99%)
Mutual labels:  prettier, formatter
Pettier
Prettier config that randomizes options and arbitrarily switches between spaces and tabs 🙄
Stars: ✭ 149 (-38.17%)
Mutual labels:  prettier, formatter

Prettyhtml Banner

Build Status lerna npm version

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.

Features

  • Indentation based primary on node-level + tag length, not content.
  • Can parse Angular, Vue or HTML5 templates.
  • Formats embedded content with prettier with respect to your local settings.
  • Doesn't change the behaviour of your attributes and tags.
  • Remove all superfluous white-space. There are two additional rules:
    • Collapses multiple blank lines into a single blank line.
    • Empty lines at the start and end of blocks are removed. (Files always end with a single newline, though.)
  • Enforce consistent output of your HTML.
  • Follows the same option philosophy as prettier.

Framework specific features

Feature Framework
HTML5 all
Self-closing custom elements vue
Self-closing none void elements vue
Case-sensitive attributes angular
Case-sensitive elements angular

Packages

Ignore element

Adding this flag before a tag will preserve from whitespace and/or attribute wrapping.

  1. Preserve from indentation, whitespace and attribute wrapping
<!--prettyhtml-ignore-->
<div></div>
  1. Preserve only from whitespace processing. This excludes indentation.
<!--prettyhtml-preserve-whitespace-->
<h1> foo </h1>
  1. Preserve only from attribute wrapping
<!--prettyhtml-preserve-attribute-wrapping-->
<h1 foo="bar" ...> foo </h1>

Install

# regular
$ npm install @starptech/prettyhtml --global

# when using proxy like sinopia/verdaccio
$ npm install @starptech/prettyhtml --global --registry=https://registry.npmjs.org/

CLI

This will process recursively all HTML files in the current directory.

$ prettyhtml example.html "./**/*.html"

Help

$ prettyhtml --help

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"
    }
  }
}

API

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.

options
options.tabWidth

The space width of your indentation level (default: 2)

options.useTabs

Use tabs instead spaces for indentation (default: false)

options.printWidth

Use different maximum line length (default: 80)

options.usePrettier

Use prettier for embedded content (default: true)

options.prettier

Use custom prettier settings for embedded content (default: local config)

options.singleQuote

Use single quote instead double quotes (default: false)

options.wrapAttributes

Force to wrap attributes (when it has multiple, default: false)

options.sortAttributes

Sort attributes alphabetically (default: false)

Editor support

  • VSCode extension (not published yet)
  • Vetur Vue tooling for VS Code

Why

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:

  • It is very easy to maintain because we have a specification and an ecosystem (and @vfile, @syntax-tree) of plugins.
  • It should be able to format any superset of HTML as long it is parseable with minor tweaks. We use a modified version of the Angular 6 template parser. There is no need to maintain multiple parser.
  • Prettyhtml doesn't try to understand all Javascript frameworks in depth even when it means that the user has to update some places manually.

Acknowledgement

Big thanks to the creators of the excellent rehype and unified ecosystem.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].