1.1.5 • Published 5 years ago

@sidouglas/prettyhtml v1.1.5

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

Prettyhtml Banner

Opinionated general formatter for your Angular, Vue, Svelte or pure HTML5 templates. Try it on the playground.

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.

Framework specific features

FeatureFramework
HTML5all
Self-closing custom elementsvue
Self-closing none void elementsvue
Case-sensitive attributesangular
Case-sensitive elementsangular

Usage

const parent = require('@sidouglas/prettyhtml');
const formatter = Object.create(parent);

formatter.cleanRoutine = async function () {
  this.prettyHtml()
    // put your clean routines in here...
    .formatTextNodes()
    .orderClassNames()
    .selfCloseTags()
    .indentPrettyContents()
    .rightTrim()
    .voidAttributes()
    .save();
};

formatter.init({
  baseDirectory: ['./src/scripts/vue/components/**/*.js', './src/scripts/vue/apps/**/*.js'],
  dialog: {
    message: 'What components/apps to tidy?',
    name: 'list',
    type: 'checkbox',
  },
  framework: {
    utilClasses: ['a-', 'l-', 'o-', 't', 'u-'],
    colOffset() {
      return this.config.isComponent(this.filePath) ? 4 : 2;
    },
  },
  isComponent(filePath) {
    return filePath.indexOf('components') > 0;
  },
  prettyHtml: {
    printWidth: 200,
    sortAttributes: true,
    wrapAttributes: true,
  },
  regex: {
    find(contents) {
      return contents.match(/(?:template.+`)([^`]*)(?:`)/)[1];
    },
    replace(content) {
      const offset = this.config.isComponent(this.filePath) ? '  ' : '';

      return `\n${content}${offset}`;
    },
  },
  ...(process.argv.slice(2)[0] ? singleFileInit : {}),
});

Packages

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago