|
| 1 | +<div align="center"> |
| 2 | + <img width="150" height="150" title="PostHTML" src="https://posthtml.github.io/posthtml/logo.svg"> |
| 3 | + <h1>Merge inline longhand</h1> |
| 4 | + <p>Merge longhand inline CSS into shorthand</p> |
| 5 | + |
| 6 | + [![Version][npm-version-shield]][npm] |
| 7 | + [![License][license-shield]][license] |
| 8 | + [![Build][travis-ci-shield]][travis-ci] |
| 9 | + [![Downloads][npm-stats-shield]][npm-stats] |
| 10 | +</div> |
| 11 | + |
| 12 | +## About |
| 13 | + |
| 14 | +This plugin uses [postcss-merge-longhand](https://github.com/cssnano/cssnano/tree/master/packages/postcss-merge-longhand) to merge longhand CSS properties found in `style=""` attributes to shorthand. |
| 15 | + |
| 16 | +Input: |
| 17 | + |
| 18 | +```html |
| 19 | +<div style="margin-top: 1px; margin-right: 2px; margin-bottom: 3px; margin-left: 4px;">Test</div> |
| 20 | +``` |
| 21 | + |
| 22 | +Output: |
| 23 | + |
| 24 | +```html |
| 25 | +<div style="margin: 1px 2px 3px 4px;">Test</div> |
| 26 | +``` |
| 27 | + |
| 28 | +## Install |
| 29 | + |
| 30 | +``` |
| 31 | +$ npm i posthtml posthtml-postcss-merge-longhand |
| 32 | +``` |
| 33 | + |
| 34 | +## Usage |
| 35 | + |
| 36 | +```js |
| 37 | +const posthtml = require('posthtml') |
| 38 | +const mergeInlineLonghand = require('posthtml-postcss-merge-longhand') |
| 39 | + |
| 40 | +const html = '<div style="margin-top: 1px; margin-right: 2px; margin-bottom: 3px; margin-left: 4px;">Test</div>' |
| 41 | + |
| 42 | +posthtml([ |
| 43 | + mergeInlineLonghand() |
| 44 | + ]) |
| 45 | + .process(html) |
| 46 | + .then(result => console.log(result.html)) |
| 47 | + |
| 48 | + // <div style="margin: 1px 2px 3px 4px;">Test</div> |
| 49 | +``` |
| 50 | + |
| 51 | +## Options |
| 52 | + |
| 53 | +### `tags` |
| 54 | + |
| 55 | +Type: `array`\ |
| 56 | +Default: `[]` |
| 57 | + |
| 58 | +Array of tag names to process. All other tags will be skipped. |
| 59 | + |
| 60 | +Example: |
| 61 | + |
| 62 | +```js |
| 63 | +const posthtml = require('posthtml') |
| 64 | +const mergeInlineLonghand = require('posthtml-postcss-merge-longhand') |
| 65 | + |
| 66 | +const html = ` |
| 67 | + <div style="margin-top: 1px; margin-right: 2px; margin-bottom: 3px; margin-left: 4px;">Test</div> |
| 68 | + <p style="margin-top: 1px; margin-right: 2px; margin-bottom: 3px; margin-left: 4px;">Test</p> |
| 69 | +` |
| 70 | + |
| 71 | +posthtml([ |
| 72 | + mergeInlineLonghand({tags: ['div']}) |
| 73 | + ]) |
| 74 | + .process(html) |
| 75 | + .then(result => console.log(result.html)) |
| 76 | + |
| 77 | + // <div style="margin: 1px 2px 3px 4px;">Test</div> |
| 78 | + // <p style="margin-top: 1px; margin-right: 2px; margin-bottom: 3px; margin-left: 4px;">Test</p> |
| 79 | +``` |
| 80 | + |
| 81 | +[npm]: https://www.npmjs.com/package/posthtml-postcss-merge-longhand |
| 82 | +[npm-version-shield]: https://img.shields.io/npm/v/posthtml-postcss-merge-longhand.svg |
| 83 | +[npm-stats]: http://npm-stat.com/charts.html?package=posthtml-postcss-merge-longhand |
| 84 | +[npm-stats-shield]: https://img.shields.io/npm/dt/posthtml-postcss-merge-longhand.svg |
| 85 | +[travis-ci]: https://travis-ci.org/posthtml/posthtml-postcss-merge-longhand/ |
| 86 | +[travis-ci-shield]: https://img.shields.io/travis/posthtml/posthtml-postcss-merge-longhand/master.svg |
| 87 | +[license]: ./LICENSE |
| 88 | +[license-shield]: https://img.shields.io/npm/l/posthtml-postcss-merge-longhand.svg |
0 commit comments