Urara-Blog/node_modules/.pnpm-store/v3/files/8d/0839ec79a6fd5e5ab51867e6a098dc56e56e01f85d643add61c55215f1039d8f0a82aff84892f967761f7e24e6431a36fde9f69a5a0cb2f6ee01cb22275629
2022-08-14 01:14:53 +08:00

59 lines
1.3 KiB
Text

"use strict"
// builtin tooling
const path = require("path")
// placeholder tooling
let sugarss
module.exports = function processContent(
result,
content,
filename,
options,
postcss
) {
const { plugins } = options
const ext = path.extname(filename)
const parserList = []
// SugarSS support:
if (ext === ".sss") {
if (!sugarss) {
try {
sugarss = require("sugarss")
} catch {} // Ignore
}
if (sugarss)
return runPostcss(postcss, content, filename, plugins, [sugarss])
}
// Syntax support:
if (result.opts.syntax && result.opts.syntax.parse) {
parserList.push(result.opts.syntax.parse)
}
// Parser support:
if (result.opts.parser) parserList.push(result.opts.parser)
// Try the default as a last resort:
parserList.push(null)
return runPostcss(postcss, content, filename, plugins, parserList)
}
function runPostcss(postcss, content, filename, plugins, parsers, index) {
if (!index) index = 0
return postcss(plugins)
.process(content, {
from: filename,
parser: parsers[index],
})
.catch(err => {
// If there's an error, try the next parser
index++
// If there are no parsers left, throw it
if (index === parsers.length) throw err
return runPostcss(postcss, content, filename, plugins, parsers, index)
})
}