https://github.com/zoubin/postcss-comment
Allow postcss to support inline comments
https://github.com/zoubin/postcss-comment
Last synced: 10 months ago
JSON representation
Allow postcss to support inline comments
- Host: GitHub
- URL: https://github.com/zoubin/postcss-comment
- Owner: zoubin
- License: mit
- Created: 2015-11-04T16:50:26.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-03-05T04:02:03.000Z (over 8 years ago)
- Last Synced: 2024-12-20T17:44:15.547Z (over 1 year ago)
- Language: JavaScript
- Size: 30.3 KB
- Stars: 22
- Watchers: 2
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# postcss-comment
[](https://www.npmjs.org/package/postcss-comment)
[](https://travis-ci.org/zoubin/postcss-comment)
[](https://david-dm.org/zoubin/postcss-comment)
[](https://david-dm.org/zoubin/postcss-comment#info=devDependencies)
Allow postcss to support inline comments.
## Usage
```bash
npm i --save-dev postcss postcss-comment
```
### As parser
```javascript
var postcss = require('postcss')
var parser = require('postcss-comment')
var fs = require('fs')
var file = __dirname + '/inline.css'
postcss()
.process(
fs.readFileSync(file, 'utf8'),
{ from: file, parser: parser }
)
.then(function (result) {
console.log(result.css)
})
```
### Hook require
```javascript
require('postcss-comment/hookRequire')
var postcss = require('postcss')
var fs = require('fs')
var file = __dirname + '/inline.css'
postcss()
.process(
fs.readFileSync(file, 'utf8'),
{ from: file }
)
.then(function (result) {
console.log(result.css)
})
```
Or:
```javascript
var postcss = require('postcss-comment/hookRequire')
var fs = require('fs')
var file = __dirname + '/inline.css'
postcss()
.process(
fs.readFileSync(file, 'utf8'),
{ from: file }
)
.then(function (result) {
console.log(result.css)
})
```
## Example
inline.css:
```css
/*
* comments//
* //comments
*/
// comments
//* comments*/
.inline-comment { /// comments
// com//ments
color: red; // comments
} // /*comments
//*/ comments
```
outputs:
```css
/*
* comments//
* //comments
*/
/* comments */
/** comments*\/ */
.inline-comment { /*\/ comments */
/* com//ments */
color: red; /* comments */
} /* /*comments */
/**\/ comments */
```