A PostHTML plugin for sort attribute of the tag based on the given order.
$ npm i -D posthtml-attrs-sorter
To follow the guidelines for writing code such as Code Guide by @mdo.
const posthtml = require('posthtml');
const attrsSorter = require('posthtml-attrs-sorter');
const htmlRaw = fs.readFileSync('path/to/file.html');
posthtml()
.use(attrsSorter({
// Options
}))
.process(htmlRaw)
.then(function(result) {
fs.writeFileSync('path/to/file.html');
})
You can also use this plugin in the PostHTML plugin to Gulp or Grunt.
- Type:
string[]
- Info:
- Strings are turned into Regular Expressions
- Use
$unknown$
to specify where the unsorted attributes are placed
- Default: http://codeguide.co/#html-attribute-order
{
"order": [
"class", "id", "name",
"data-.+", "ng-.+", "src",
"for", "type", "href",
"values", "title", "alt",
"role", "aria-.+",
"$unknown$"
]
}
An array of attributes in the correct order.
See the Releases section of our GitHub project for changelogs for each release version.
MIT.