包详细信息

posthtml-beautify

posthtml6.5kMIT0.7.0

A posthtml plugin to beautify you html files

html, posthtml, posthtml-plugin, beautify

自述文件

posthtml-beautify

A posthtml plugin to beautify you html files

Travis Build Statusnodenpm versionDependency StatusXO code styleCoveralls status

npm downloadsnpmPackage Quality

Why?

Format your html and inline css markup according to the HTML5 syntax Style Guide, Code Guide. Full list of supported options:

  • [x] Transform lower case element names
  • [x] Transform lower case attribute names
  • [x] Only double quotes
  • [x] Close all html elements
  • [x] Removing trailing slash in self-closing
  • [x] Removes spaces at the equal sign
  • [x] Add blank lines to separate large or logical code blocks
  • [x] Add 2 spaces of indentation. Do not use TAB.
  • [x] Add language attribute
  • [ ] Add character encoding
  • [x] Attribute order
  • [x] Boolean attributes
  • [ ] Creates file from the inline styles
  • [ ] Create scoped class name (use css-modules) instead inline styles
  • [ ] validate elements and attributes name
  • [x] parses Internet Explorer Conditional Comments (not support Downlevel-revealed and valid version, htmlparse2 invalid parses)

Install

npm i -S posthtml posthtml-beautify

Note: This project is compatible with node v10+

Usage

import {readFileSync, writeFileSync} from 'fs';
import posthtml from 'posthtml';
import beautify from 'posthtml-beautify';

const html = readFileSync('input.html', 'utf8');

posthtml()
  .use(beautify({rules: {indent: 4}}))
  .process(html)
  .then(result => {
    writeFileSync('output.html', result.html);
  });

Returns html-formatted according to rules based on the use HTML5 syntax Style Guide, Code Guide with custom settings indent: 4

Example

Options

rules

Type: Object
Default:

  • Indent
    Type: Number|String(only tab)
    Default: 2
    Description: A numeric value indicates specifies the number of spaces. The string value only tab

  • blankLines
    Type: String|Boolean(only false)
    Default: '\n'
    Description: Add or remove blank lines to separate large or logical code blocks

  • eol (end of line)
    Type: String
    Default: '\n'
    Description: As value is a string symbol which is added to the end of the row

  • eof (end of file)
    Type: String|Boolean
    Default: '\n'
    Description: As value is a string symbol which is added to the end of the file and will not adds if you specify a boolean value of false

  • maxlen
    Type: Number
    Default: '80'
    Description: checks for the max length of the content, indents the whole content to a new line

  • sortAttr
    Type: Boolean
    Default: false
    Description: Sort the order of attributes in elements

  • lang
    Type: String | Boolean(only false)
    Default: false
    Description: Add a lang attribute in elements, eg: { lang: 'fr' }

  • commentFormat
    Type: Boolean
    Default: true
    Description: Formats the comments. It does the following

    • If there are multi line comments then there would be leading and trailing newline like this

      // Input
      
      <!-- multiline 
      comments-->
      
      // Output
      
      <!-- 
      multiline 
      comments
      -->
    • If there is a single line comment, it would make it to a single line with the comment starting and ending notation in same line

      Input

      <!-- 
        singleline comments
      -->

      Output

      <!-- singleline comments -->

mini

Type: Object
Default:

  • removeAttribute
    Type: String|Boolean
    Default: false
    Description: Removes attributes that do not matter. The string value only empty

jsBeautifyOptions

Type: Object
Default: All options as per package js-beautify except, indent_level because calculated and set according to context

Related

更新日志

0.7.0 (2020-06-17)

  • build: update dep dev (e2e8762)
  • fix: escape character in regexp (b77ecca)
  • fix: get matching (e2c32da)
  • fix: global matching (5afbfec)
  • fix: match content (dbd49a2)
  • fix: trim parts (95e26c1)
  • style: trailing spaces (84fe2de)
  • style: trailing spaces (b8c72eb)
  • refactor: code orderinh (83a4fe9)
  • refactor: commentsFormatting (b0be940)
  • refactor: small changes (a239b34)
  • docs: added docs for commentFormat option (9e6e7a3)
  • feat: added newline formatting for comments (9784534)

0.6.0 (2020-05-28)

  • 0.6.0 (581972b)
  • build: update changelog (f877707)
  • build: update dep dev (b0df484)
  • refactor: using walk method and added some tests (c5821bc)
  • feat: language attribute support (71aa6c2)

0.5.0 (2020-05-26)

  • 0.5.0 (3046e89)
  • Update index.js (2c702ac)
  • build: update changelog (541091a)
  • build: update dep dev (5f66365)
  • style: after update dev dep and lint (cead49c)
  • refactor: added keys length check for perf (58c56c9)
  • refactor: extraced sort logic (5382e21)
  • refactor: refactore checks for sortAttrs (a2c1b53)
  • refactor: removed + sign for positive (3e7ff26)
  • feat: sorting of attributes (0ef866b)
  • ci: added github action (1fbfb1b)

0.4.0 (2020-04-29)

0.3.1 (2019-10-11)

0.3.0 (2019-09-16)

0.2.6 (2019-06-18)

0.2.5 (2018-11-25)

0.2.4 (2018-11-22)

0.2.3 (2018-11-22)

0.2.2 (2018-11-21)

0.2.1 (2018-11-21)

  • 0.2.1 (1ca2151)
  • Create CNAME (d5a27c6)
  • Delete CNAME (cf4f194)
  • build: add changelog file (c0f17e1)
  • build: add config xo, close #221 (d16e6a2), closes #221
  • build: add xo space (efebefc)
  • build: migration to 4 version (1f0a798)
  • build: update and perf for script and config system (8b03cc5)
  • build: update changelog (b2e5c91)
  • build: update changelog (95aedb5)
  • build: update dep dev (60633a5)
  • build: update depDev (8df8e9d)
  • build: update rules for eslint and clinton (c374a4f)
  • perf: downgrade for ie 11, close #224 (74a99f5), closes #224
  • perf: drop support old node (01d4c4e)
  • perf: not need return promise because posthtml promise (b955f3b)
  • test: fix forgot change plain (f564e61)
  • test: remove because this remove from new version posthtml (34dd65e)
  • style: according stylelint (e757486)
  • style: according stylelint (fcddb21)
  • style: according stylelint (38cdec3)
  • style: according stylelint (74140b2)
  • ci: add new node version (e3f0a0b)
  • docs: change user name (dc7eaa9)

0.2.0 (2018-01-25)

  • 0.2.0 (a0def3b)
  • fix: fucking htmlparser2 incorrect parse (d4996dc)
  • test: drop test with async (f3c3cfe)
  • test: fix lost readFile (7df4222)
  • test: for blank lines, #217, #216 (6e51770), closes #217 #216
  • test: only test-* file (30c1ec5)
  • test: remove process and read file to utils (92b2c40)
  • test: return commnet tests (5993060)
  • test: revrite check api to async (6f94812)
  • test: update according perf detect sync/async (06680b2)
  • docs: add description for balnk lines option (5543e74)
  • docs: drop license, github have tab license (8997330)
  • docs: drop sync option because this resolve in posthtml (6de6b0b)
  • feat: option blank lines, close #216, close #217 (00ce993), closes #216 #217
  • perf: detect sync async from tree options (13e8a3e)
  • perf: rewrited to the promise (793f487)
  • perf: trim attributes value (421a6f1)
  • build: update changelog (0690f1c)

0.1.11 (2018-01-16)

  • 0.1.11 (c7e0dc0)
  • revert: drop array includes (a4576b5)
  • build: fix add export modules plugin for babel, close #221 (5c0703f), closes #221
  • build: update changelog (b92923d)
  • perf: drop array includes (665b6d0)

0.1.10 (2018-01-15)

  • 0.1.10 (bd9169c)
  • fix: cannot find module babel-runtime, close #213 (b6c4bbc), closes #213
  • build: fix postpublish script (b7f8251)
  • build: update changelog (0b3e6d5)

0.1.9 (2018-01-10)

0.1.8 (2017-09-06)

  • 0.1.8 (36b6812)
  • chore: 0.1.7 (393986d)
  • chore: add @commitlint (0432ab6)
  • chore: not used anymore (fbf65d6)
  • chore: Update changelog (cb092ec)
  • chore: Update changelog (6019008)
  • chore: update commit lint (eb0522e)
  • chore: update depDev (ecab96d)
  • chore(package): update husky to version 0.13.4 (03e1711)
  • fix: incorrect build main file destitnation, close #206 (8a3b90f), closes #206
  • style: fixed lint report (43644c6)

0.1.6 (2017-05-25)

  • 0.1.6 (07a4def)
  • docs: add online service, close #57 (c498d81), closes #57
  • docs: change ci badges to master, close #161 (52575eb), closes #161
  • docs: fix lint (2f4a98e)
  • docs: prebuild (3e7b3a7)
  • docs: update (2971d81)
  • chore: add commit at prepush (8b5cc0e)
  • chore: add yarn (63cacab)
  • chore: change to folder (6ef496f)
  • chore: no-yarn on publish (b776df7)
  • chore: remove docs build, webpack freezed (e57006d)
  • chore: remove not use pkd (97b498a)
  • chore: update (40eeaee)
  • chore(changelog): Update changelog vnpm view posthtml-beautify version (dbb9d4e)
  • chore(package): update babel-cli to version 6.24.1 (11c84e1)
  • chore(package): update babel-eslint to version 7.2.2 (82b6c7e)
  • chore(package): update babel-eslint to version 7.2.3 (fbefced)
  • chore(package): update babel-preset-babili to version 0.1.2 (c4ad7a9)
  • chore(package): update babel-preset-env to version 1.4.0 (d18f8cf)
  • chore(package): update babel-register to version 6.24.1 (8cb25c3)
  • chore(package): update clinton to version 0.12.0 (458c86c)
  • chore(package): update conventional-changelog-lint to version 1.1.8 (d243971)
  • chore(package): update conventional-changelog-lint to version 1.1.9 (38ab556)
  • chore(package): update coveralls to version 2.13.1 (9ec4444)
  • chore(package): update eslint to version 3.19.0 (86c3dc4)
  • chore(package): update eslint-config-xo to version 0.18.2 (975cbb7)
  • chore(package): update eslint-plugin-html to version 2.0.2 (6dc7148)
  • chore(package): update eslint-plugin-html to version 2.0.3 (d0f5a7a)
  • chore(package): update np to version 2.14.1 (69b6ba8)
  • chore(package): update nyc to version 10.3.0 (eb20f11)
  • chore(package): update nyc to version 10.3.2 (ecb4b87)
  • chore(package): update updtr to version 1.0.0 (e18bd7d)
  • fix: remove build docs to prepush (e559371)
  • perf: options default (a575164)

0.1.5 (2017-03-23)

  • 0.1.5 (8cc6cc2)
  • docs(readme): add description for option mini (b86bb89)
  • docs(readme): add Greenkeeper badge (fc7c34c)
  • docs(readme): remove greenkeaper badge (e665a9a)
  • test(test-plugin): test options mini remove empty attributes (f22fc3f)
  • test(test-plugin): trim attributes property (069a828)
  • feat(index): add options mini remove empty attributes (a7834fb)
  • perf(index): trim attributes property, close #166 (f5334c3), closes #166
  • fix(index): transform to lower attribute name (a88f1de)
  • chore(changelog): Update changelog v0.1.4 (b4d7fde)
  • chore(package): update babel-preset-babili to version 0.0.11 (b5e09b2)
  • chore(package): update dependencies (d1e27bb)
  • chore(package): update posthtml-parser to version 0.2.1 (fe2fcbe)

0.1.4 (2017-02-08)

  • 0.1.4 (bf56175)
  • fix(*): cannot find module es6.map, close #153 (7848934), closes #153
  • chore(changelog): Update changelog v0.1.3 (ad995e1)
  • chore(package): update eslint-plugin-ava to version 4.1.0 (443be04)

0.1.3 (2017-02-07)

  • 0.1.3 (cf8ab76)
  • revert(index): revert reflect because throw error (cc563cf)
  • style(*): add eol (2b56d2c)
  • test(package): update reg extension (124f0d6)
  • chore(changelog): Update changelog v0.1.2 (6c3ae30)
  • chore(package): add babel-polyfill (2bddb87)
  • chore(package): update ava to version 0.18.1 (9272230)
  • chore(package): update ava-codemods to version 0.3.1 (c7a4433)
  • chore(package): update babel-cli to version 6.22.2 (84ad419)
  • chore(package): update babel-preset-babili to version 0.0.10 (fd97cf9)
  • chore(package): update babel-preset-env to version 1.1.8 (f84450d)
  • chore(package): update babel-register to version 6.22.0 (4a3b2a9)
  • chore(package): update clinton to version 0.11.0 (32bf0cb)
  • chore(package): update coveralls to version 2.11.16 (0bbadc8)
  • chore(package): update deepmerge to version 1.3.2 (eec707b)
  • chore(package): update eslint to version 3.15.0 (e543e51)
  • chore(package): update eslint-plugin-ava to version 4.0.1 (2590cc2)
  • chore(package): update eslint-plugin-babel to version 4.0.1 (bc474a7)
  • chore(package): update eslint-plugin-html to version 2.0.0 (cfb1bbe)
  • chore(package): update husky to version 0.13.1 (943bcc2)
  • chore(package): update nyc to version 10.1.2 (63dca2c)
  • chore(package): update posthtml to version 0.9.2 (779f276)
  • perf(index): use reflect, close #130 (139e819), closes #130
  • fix(package): change node version type (be08330)

0.1.2 (2016-12-30)

  • 0.1.2 (571279e)
  • fix(package): change pkg name in postpublish (d0cb61b)
  • fix(rules): return to unix notation, close #112 (0f51218), closes #112
  • chore(changelog): Update changelog v0.1.10 (193db71)
  • chore(package): update clinton to version 0.10.0 (96b0794)

0.1.1 (2016-12-29)

  • 0.1.1 (d1570ad)
  • Update readme.md (f7426d8)
  • Update readme.md (257eac0)
  • chore(changelog): Update changelog (9257e32)
  • chore(package): add version on prepublich commit (7bbe068)
  • chore(package): change preset-es2015 to preset-env, close #104 (85a3309), closes #104
  • chore(package): fix clinton recommendation for ava (d02b136)
  • chore(package): update ava to version 0.17.0 (9c9b5ee)
  • chore(package): update babel-eslint to version 7.1.1 (98011e8)
  • chore(package): update babel-preset-babili to version 0.0.9 (b4b30d8)
  • chore(package): update babel-preset-es2015 to version 6.18.0 (04b6065)
  • chore(package): update clinton to version 0.9.0 (31cf033)
  • chore(package): update conventional-changelog-lint to version 1.1.0 (360299e)
  • chore(package): update coveralls to version 2.11.15 (ee0e4e7)
  • chore(package): update depDev (a9958b1)
  • chore(package): update eslint to version 3.11.1 (66f65bb)
  • chore(package): update eslint to version 3.12.1 (588d49a)
  • chore(package): update eslint to version 3.8.0 (bc64da5)
  • chore(package): update eslint-plugin-ava to version 4.0.0 (2ea2ce4)
  • chore(package): update eslint-plugin-babel to version 4.0.0 (d0e94c5)
  • chore(package): update eslint-plugin-html to version 1.7.0 (a7eef18)
  • chore(package): update np to version 2.12.0 (c2c483f)
  • chore(package): update nyc to version 10.0.0 (389a0fb)
  • chore(package): update nyc to version 8.3.2 (14aa613)
  • chore(package): update updtr to version 0.2.3 (75fbd0e)
  • docs(readme): update options (4f48e12)
  • test(*): fix path (9b545f4)
  • test(package): add node 7 (5474a17)
  • ci(*): add node 7 (a00e10c)
  • perf(*): change assign-deep to deepmerge (58659ea)
  • perf(rules): change property to os.eol, close #101 (0d04acd), closes #101
  • feat(*): transform to lower case element name, close #110 (6795c08), closes #110
  • style(index): fix no-useless-escape (784f2b2)
  • fix(package): add lost pkg (b4c7270)
  • fix(package): to lowercase changelog in postpublish (788c91e)

0.1.0 (2016-10-12)

  • 0.1.0 (74183a3)
  • docs(readme): add description for options sync (dcf6b06)
  • docs(readme): add license (1fb27b7)
  • test(test-plugin): add tests for sync mode (8b90dd1)
  • test(test-plugin): improving processing (98da81c)
  • feat(index): add options sync mode, fixed #70 (912291e), closes #70
  • chore(changelog): Update changelog (be989a3)
  • chore(package): update ava-codemods to version 0.3.0 (5f1148b)
  • chore(package): update babel-eslint to version 7.0.0 (a590ee0)
  • chore(package): update babel-preset-babili to version 0.0.5 (7db66ca)
  • chore(package): update coveralls to version 2.11.14 (df69bbb)
  • chore(package): update devDependencies and dependencies (e2e8b7f)
  • chore(package): update eslint to version 3.7.0 (872aa33)
  • chore(package): update eslint-config-xo to version 0.17.0 (a1af04f)
  • chore(package): update eslint-formatter-pretty to version 1.0.1 (3497d0e)
  • chore(package): update eslint-plugin-html to version 1.5.3 (b6ec642)
  • chore(package): update husky to version 0.11.9 (d7ec27f)

0.0.6 (2016-09-19)

  • 0.0.6 (9b3f61a)
  • fix(*): fix last indent if only one element (def6fcd)
  • fix(package): fix clinton report (46b52c9)
  • docs(readme): update result output.html (2610d49)
  • chore(changelog): Update changelog (2b983b5)
  • chore(package): add linting javascript in html files (ce36a7e)
  • chore(package): change babel-min to babili, fixed #54 (ea43737), closes #54
  • chore(package): update ava to version 0.16.0 (5f6300b)
  • chore(package): update babel-preset-es2015 to version 6.14.0 (8ac62c6)
  • chore(package): update clinton to version 0.8.0 (a083257)
  • chore(package): update coveralls to version 2.11.13 (9cce017)
  • chore(package): update eslint to version 3.4.0 (d1665bf)
  • chore(package): update eslint-formatter-pretty to version 0.3.1 (0b36d24)
  • chore(package): update eslint-formatter-pretty to version 1.0.0 (11a3056)
  • chore(package): update eslint-plugin-ava to version 3.0.0 (6b489a8)
  • chore(package): update eslint-plugin-xo to version 1.0.0 (0b297e1)
  • chore(package): update husky to version 0.11.7 (3961263)
  • chore(package): update np to version 2.8.0 (f9f8774)
  • chore(package): update nyc to version 8.1.0 (52bb205)
  • chore(package): update nyc to version 8.3.0 (a5285cf)
  • perf(index): add line break for last node on level 0, fixed #38 (255c100), closes #38

0.0.5 (2016-08-04)

  • 0.0.5 (b306412)
  • fix(*): fix according to clinton recommendations (b791b71)
  • fix(*): incorrect write value (2ba2a13)
  • chore(changelog): Update changelog (d7ac7fe)
  • chore(package): add testen, fixed #23 (69a5bad), closes #23
  • chore(package): update devDep (a3401bf)
  • refactor(*): adds a parser ie conditional comments, fixed #8 (a5b6ffc), closes #8
  • refactor(index.js): add tmp conditional internet explorer comment (4f58d27)

0.0.4 (2016-08-01)

  • 0.0.4 (0c9f3e0)
  • docs(readme): add description for new feature eof (54457fa)
  • feat(eof): add EOF feature #29 (cff9c3a), closes #29
  • chore(changelog): Update changelog (69939c3)
  • chore(package): update babel-register to version 6.11.6 (a66b160)
  • chore(package): update coveralls to version 2.11.12 (29b1d6b)
  • chore(package): update nyc to version 7.1.0 (c1bcd7f)

0.0.3 (2016-07-22)

  • 0.0.3 (e80f9af)
  • fix(package): lose dependencies pkg (ed033da)
  • chore(changelog): Update changelog (3ef2d80)

0.0.2 (2016-07-22)

  • 0.0.2 (55d93aa)
  • chore(*): fixed #17, add ignore to clinton config and edit editorconfig (4a6a426), closes #17
  • chore(package): add #18, auto node package publish (6b211f1), closes #18
  • chore(package): add chlog lint&generator fixed #16 (e002543), closes #16
  • chore(package): add key any branch on publish (358def9)
  • chore(package): fixed #19, change config clinton (203885a), closes #19
  • chore(package): update devDep (3ed4857)
  • docs(readme): add badge node support (0afc758)
  • refactor(index): remove double call attrsBoolean (4fe7a56)
  • test(*): fixed #5, add test with plugins (c6418b6), closes #5
  • style(.editorconfig): not need final new line for html (9a38065)
  • fix(index): fixed #15, incorrect set indent with posthtml-modules (f072515), closes #15

0.0.1 (2016-07-08)

  • Added posthtml in devDependencies for testing (b32764c)
  • bump (fae6efa)
  • bump (9fee393)
  • Fixed #11, now rules as property (0d2d4f2), closes #11
  • Fixed #12, added clinton (2a0eef9), closes #12
  • Fixed #12, change xo to eslint (4774642), closes #12
  • Fixed appveyor config (670d1c2)
  • Fixed linter report error (0a9726d)
  • not to put preset min (a1d4c39)
  • Remove comment (ace0859)
  • Remove comment (0d0c702)
  • v0.0.0 ... v0.0.1 (055eedb)
  • chore(package): update babel-preset-min to version 0.1.15 (9dc2372)
  • chore(package): update posthtml to version 0.9.0 (14b09bf)

0.0.0 (2016-07-01)