-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit df6f6a7
Showing
25 changed files
with
1,921 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = tab | ||
indent_size = 2 | ||
insert_final_newline = true | ||
tab_width = 4 | ||
trim_trailing_whitespace = true | ||
block_comment_start = /* | ||
block_comment = * | ||
block_comment_end = */ | ||
|
||
[*.{cmd,bat}] | ||
end_of_line = crlf | ||
|
||
[{package.json,*.yml}] | ||
indent_style = space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
{ | ||
"parserOptions": { | ||
"sourceType": "script", | ||
"impliedStrict": false | ||
}, | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": [ | ||
"standard" | ||
], | ||
"root": true, | ||
"rules": { | ||
"comma-dangle": [ | ||
"error", | ||
{ | ||
"arrays": "always-multiline", | ||
"objects": "always-multiline", | ||
"imports": "always-multiline", | ||
"exports": "always-multiline", | ||
"functions": "never" | ||
} | ||
], | ||
"comma-spacing": [ | ||
"error", | ||
{ | ||
"after": true, | ||
"before": false | ||
} | ||
], | ||
"indent": [ | ||
"error", | ||
"tab", | ||
{ | ||
"SwitchCase": 1 | ||
} | ||
], | ||
"no-tabs": [ | ||
"off" | ||
], | ||
"no-var": [ | ||
"error" | ||
], | ||
"prefer-arrow-callback": [ | ||
"error" | ||
], | ||
"prefer-const": [ | ||
"error" | ||
], | ||
"quotes": [ | ||
"error", | ||
"double" | ||
], | ||
"semi": [ | ||
"error", | ||
"always", | ||
{ | ||
"omitLastInOneLineBlock": false | ||
} | ||
], | ||
"strict": [ | ||
"error", | ||
"safe" | ||
] | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"test/**/*" | ||
], | ||
"env": { | ||
"mocha": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Created by https://www.gitignore.io/api/node | ||
|
||
### Node ### | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
|
||
|
||
# End of https://www.gitignore.io/api/node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
*.log | ||
*.pid | ||
*.seed | ||
.editorconfig | ||
.eslintrc* | ||
.gitignore | ||
.grunt | ||
.lock-wscript | ||
.node_repl_history | ||
.nyc_output | ||
.stylelintrc* | ||
.travis.yml | ||
.vscode | ||
appveyor.yml | ||
coverage | ||
gulpfile.js | ||
lib-cov | ||
logs | ||
node_modules | ||
npm-debug.log* | ||
pids | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
dist: trusty | ||
sudo: false | ||
language: node_js | ||
|
||
node_js: | ||
- stable | ||
- 4 | ||
|
||
after_script: | ||
- npm run report-coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 刘祺 | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
PostCSS Syntax | ||
==== | ||
|
||
[![NPM version](https://img.shields.io/npm/v/postcss-syntax.svg?style=flat-square)](https://www.npmjs.com/package/postcss-syntax) | ||
[![Travis](https://img.shields.io/travis/gucong3000/postcss-syntax.svg)](https://travis-ci.org/gucong3000/postcss-syntax) | ||
[![Codecov](https://img.shields.io/codecov/c/github/gucong3000/postcss-syntax.svg)](https://codecov.io/gh/gucong3000/postcss-syntax) | ||
[![David](https://img.shields.io/david/gucong3000/postcss-syntax.svg)](https://david-dm.org/gucong3000/postcss-syntax) | ||
|
||
<img align="right" width="95" height="95" | ||
title="Philosopher’s stone, logo of PostCSS" | ||
src="http://postcss.github.io/postcss/logo.svg"> | ||
|
||
[PostCSS](https://github.com/postcss/postcss) auto syntax switch tool | ||
|
||
## Getting Started | ||
|
||
First thing's first, install the module: | ||
|
||
``` | ||
npm install postcss-syntax --save-dev | ||
``` | ||
|
||
If you want support SCSS/SASS/LESS/SugarSS syntax, you need to install these module: | ||
|
||
- SCSS: [PostCSS-SCSS](https://github.com/postcss/postcss-scss) | ||
- SASS: [PostCSS-SASS](https://github.com/aleshaoleg/postcss-sass) | ||
- LESS: [PostCSS-LESS](https://github.com/shellscape/postcss-less) | ||
- SugarSS: [SugarSS](https://github.com/postcss/sugarss) | ||
|
||
If you want support HTML (and HTML-like)/Markdown/styled-components file format, you need to install these module: | ||
|
||
- SASS: [PostCSS-Markdown](https://github.com/gucong3000/postcss-markdown) | ||
- LESS: [PostCSS-Styled](https://github.com/gucong3000/postcss-styled) | ||
- SCSS: [PostCSS-HTML](https://github.com/gucong3000/postcss-html) | ||
|
||
## Use Cases | ||
|
||
```js | ||
const postcss = require('postcss'); | ||
const syntax = require('postcss-syntax')({ | ||
processors: [ | ||
{ | ||
test: /\.(?:[sx]?html?|[sx]ht|vue|ux|php)$/i, | ||
split: 'html', | ||
}, | ||
{ | ||
test: /\.(?:markdown|md)$/i, | ||
split: 'markdown', | ||
}, | ||
{ | ||
test: /\.(?:m?[jt]sx?|es\d*|pac)$/i, | ||
split: 'styled', | ||
}, | ||
{ | ||
// custom file extension | ||
test: /\.postcss$/i, | ||
lang: 'scss' | ||
}, | ||
{ | ||
// custom syntax engine | ||
test: /\.customcss$/i, | ||
lang: 'custom' | ||
}, | ||
], | ||
css: postcss, | ||
sass: require('postcss-sass'), | ||
scss: require('postcss-scss'), | ||
less: require('postcss-less'), | ||
sugarss: require('sugarss'), | ||
// custom syntax engine | ||
custom: require('postcss-custom-syntax'), | ||
|
||
}); | ||
postcss(plugins).process(source, { syntax: syntax }).then(function (result) { | ||
// An alias for the result.css property. Use it with syntaxes that generate non-CSS output. | ||
result.content | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"use strict"; | ||
const PostCssRoot = require("postcss/lib/root"); | ||
const LazyResult = require("postcss/lib/lazy-result").prototype; | ||
const runRoot = LazyResult.run; | ||
|
||
class Document extends PostCssRoot { | ||
toString (stringifier) { | ||
return super.toString(stringifier || { | ||
stringify: require("./stringify"), | ||
}); | ||
} | ||
|
||
each (callback) { | ||
const result = this.nodes.map(node => node.each(callback)); | ||
return result.every(result => result !== false) && result.pop(); | ||
} | ||
|
||
append () { | ||
this.last.append.apply( | ||
this.last, | ||
Array.from(arguments) | ||
); | ||
return this; | ||
} | ||
|
||
prepend () { | ||
this.first.prepend.apply( | ||
this.first, | ||
Array.from(arguments) | ||
); | ||
return this; | ||
} | ||
|
||
insertBefore (exist, add) { | ||
exist.prepend(add); | ||
return this; | ||
} | ||
|
||
insertAfter (exist, add) { | ||
exist.append(add); | ||
return this; | ||
} | ||
} | ||
|
||
function isPromise (obj) { | ||
return typeof obj === "object" && typeof obj.then === "function"; | ||
} | ||
|
||
function runDocument (plugin) { | ||
let result = this.result; | ||
result.lastPlugin = plugin; | ||
result = result.root.nodes.map(root => { | ||
const childResult = root.toResult(result.opts); | ||
try { | ||
return plugin(root, childResult); | ||
} catch (error) { | ||
this.handleError(error, plugin); | ||
throw error; | ||
} | ||
}); | ||
if (result.some(isPromise)) { | ||
result = Promise.all(result); | ||
} | ||
return result; | ||
} | ||
|
||
LazyResult.run = function run () { | ||
return (this.result.root instanceof Document ? runDocument : runRoot).apply(this, arguments); | ||
}; | ||
|
||
module.exports = Document; |
Oops, something went wrong.