mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-02 07:09:30 +08:00
29 lines
722 B
Text
29 lines
722 B
Text
module.exports = {
|
|
|
|
itMatchesOne(arr, term) {
|
|
return arr.some((i) => term.search(i) >= 0);
|
|
},
|
|
|
|
parseAttrSelector(node) {
|
|
const { content } = node;
|
|
const regex = /(^class|^id)([*^?~|$=]*)+(?:("\s*)([^"\\]*?(?:\\.[^"\\]*)*?)(\s*")|('\s*)([^'\\]*?(?:\\.[^'\\]*)*?)(\s*'))/i;
|
|
|
|
const [type, operator, head, classes, foot] = content
|
|
.split(regex)
|
|
.filter((part) => part);
|
|
|
|
return {
|
|
type,
|
|
operator,
|
|
head,
|
|
classes: classes ? classes.split(' ').map((c) => c.replace(/"|'/g, '')) : [],
|
|
foot,
|
|
};
|
|
},
|
|
|
|
attrStringify({
|
|
type, operator, head, classes, foot,
|
|
}) {
|
|
return `${type}${operator || ''}${head || ''}${classes.join(' ')}${foot || ''}`;
|
|
},
|
|
};
|