1 | "use strict"
|
2 |
|
3 |
|
4 | const path = require("path")
|
5 |
|
6 |
|
7 | const postcss = require("postcss")
|
8 |
|
9 |
|
10 | let sugarss
|
11 |
|
12 | module.exports = function processContent(result, content, filename, options) {
|
13 | const plugins = options.plugins
|
14 | const ext = path.extname(filename)
|
15 |
|
16 | const parserList = []
|
17 |
|
18 |
|
19 | if (ext === ".sss") {
|
20 | if (!sugarss) {
|
21 | try {
|
22 | sugarss = require("sugarss")
|
23 | } catch (e) {
|
24 |
|
25 | }
|
26 | }
|
27 | if (sugarss) return runPostcss(content, filename, plugins, [sugarss])
|
28 | }
|
29 |
|
30 |
|
31 | if (result.opts.syntax && result.opts.syntax.parse) {
|
32 | parserList.push(result.opts.syntax.parse)
|
33 | }
|
34 |
|
35 |
|
36 | if (result.opts.parser) parserList.push(result.opts.parser)
|
37 |
|
38 | parserList.push(null)
|
39 |
|
40 | return runPostcss(content, filename, plugins, parserList)
|
41 | }
|
42 |
|
43 | function runPostcss(content, filename, plugins, parsers, index) {
|
44 | if (!index) index = 0
|
45 | return postcss(plugins)
|
46 | .process(content, {
|
47 | from: filename,
|
48 | parser: parsers[index],
|
49 | })
|
50 | .catch(err => {
|
51 |
|
52 | index++
|
53 |
|
54 | if (index === parsers.length) throw err
|
55 | return runPostcss(content, filename, plugins, parsers, index)
|
56 | })
|
57 | }
|