Enforce full-length hex colour codes using PostHTML. #abc => #aabbcc
- It's driven by the library: color-shorthand-hex-to-six-digit.
IMPORTANT. If you are using XHTML and closing slashes on singleton tags (img
, br
and others) are important for you, don't use this plugin. Use its API color-shorthand-hex-to-six-digit directly.
Table of Contents generated with DocToc
$ npm i posthtml-color-shorthand-hex-to-six-digit --save-dev
This PostHTML plugin is aimed at email template developers. Certain email software will not render HTML shorthand hex color codes (like #ccc
) within tag attributes. Instead, you have to put full-length hex codes (like #cccccc
). This library will automatically convert any shorthand hex color codes into full-length, and as a bonus, will convert any uppercase letters within hex color codes into lowercase.
Just add posthtml-color-shorthand-hex-to-six-digit
onto your PostHTML plugins list.
const fs = require('fs');
const posthtml = require('posthtml');
const convertHex = require('posthtml-color-shorthand-hex-to-six-digit');
posthtml()
.use(convertHex())
.process(html/*, options */)
.then(result => fs.writeFileSync('./after.html', result.html));
$ npm i -D gulp
$ npm i -D gulp-posthtml
$ npm i -D posthtml-color-shorthand-hex-to-six-digit
gulp.task('build', function() {
var plugins = [
require('posthtml-color-shorthand-hex-to-six-digit')()
];
return gulp.src('./build/**/*.html')
.pipe(posthtml(plugins))
.pipe(gulp.dest('./dist'));
})
All contributions are welcome. Please stick to Standard JavaScript notation and supplement the test.js
with new unit tests covering your feature(s).
If you see anything incorrect whatsoever, do raise an issue on the core library.
MIT License (MIT)
Copyright (c) 2017 Codsen Ltd, Roy Revelt
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.