|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Rev | Line | |
|---|
| [9af201e] | 1 | "use strict"
|
|---|
| 2 |
|
|---|
| 3 | // builtin tooling
|
|---|
| 4 | const path = require("path")
|
|---|
| 5 |
|
|---|
| 6 | // placeholder tooling
|
|---|
| 7 | let sugarss
|
|---|
| 8 |
|
|---|
| 9 | module.exports = function processContent(
|
|---|
| 10 | result,
|
|---|
| 11 | content,
|
|---|
| 12 | filename,
|
|---|
| 13 | options,
|
|---|
| 14 | postcss
|
|---|
| 15 | ) {
|
|---|
| 16 | const { plugins } = options
|
|---|
| 17 | const ext = path.extname(filename)
|
|---|
| 18 |
|
|---|
| 19 | const parserList = []
|
|---|
| 20 |
|
|---|
| 21 | // SugarSS support:
|
|---|
| 22 | if (ext === ".sss") {
|
|---|
| 23 | if (!sugarss) {
|
|---|
| 24 | try {
|
|---|
| 25 | sugarss = require("sugarss")
|
|---|
| 26 | } catch {} // Ignore
|
|---|
| 27 | }
|
|---|
| 28 | if (sugarss)
|
|---|
| 29 | return runPostcss(postcss, content, filename, plugins, [sugarss])
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | // Syntax support:
|
|---|
| 33 | if (result.opts.syntax?.parse) {
|
|---|
| 34 | parserList.push(result.opts.syntax.parse)
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | // Parser support:
|
|---|
| 38 | if (result.opts.parser) parserList.push(result.opts.parser)
|
|---|
| 39 | // Try the default as a last resort:
|
|---|
| 40 | parserList.push(null)
|
|---|
| 41 |
|
|---|
| 42 | return runPostcss(postcss, content, filename, plugins, parserList)
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | function runPostcss(postcss, content, filename, plugins, parsers, index) {
|
|---|
| 46 | if (!index) index = 0
|
|---|
| 47 | return postcss(plugins)
|
|---|
| 48 | .process(content, {
|
|---|
| 49 | from: filename,
|
|---|
| 50 | parser: parsers[index],
|
|---|
| 51 | })
|
|---|
| 52 | .catch(err => {
|
|---|
| 53 | // If there's an error, try the next parser
|
|---|
| 54 | index++
|
|---|
| 55 | // If there are no parsers left, throw it
|
|---|
| 56 | if (index === parsers.length) throw err
|
|---|
| 57 | return runPostcss(postcss, content, filename, plugins, parsers, index)
|
|---|
| 58 | })
|
|---|
| 59 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.