-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Showing
9 changed files
with
311 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,44 @@ | ||
/** @module */ | ||
import postcssPlugin from '../helpers/postcss_plugin' | ||
import postcssNesting from 'postcss-nesting' | ||
import postcssIsPseudoClass from '@csstools/postcss-is-pseudo-class' | ||
|
||
const { Rule: applyPostCSSNesting } = postcssNesting() | ||
|
||
const matcher = /:is\((?:section|:root)\b/ | ||
|
||
export const nesting = postcssPlugin( | ||
'marpit-postcss-nesting', | ||
() => (root, helpers) => { | ||
const rules = [] | ||
|
||
// Note: Use walk instead of walkRules to include nested rules | ||
root.walk((node) => { | ||
if (node.type !== 'rule') return | ||
|
||
rules.push(node) | ||
node.__marpitNestingOriginalSelector = node.selector | ||
}) | ||
|
||
// Apply postcss-nesting | ||
root.walkRules((rule) => applyPostCSSNesting(rule, helpers)) | ||
|
||
const { Rule: applyPostCSSIsPseudoClass } = postcssIsPseudoClass({ | ||
onComplexSelector: 'warning', | ||
}).prepare() | ||
|
||
for (const rule of rules) { | ||
if ( | ||
rule.__marpitNestingOriginalSelector !== rule.selector && | ||
matcher.test(rule.selector) | ||
) { | ||
// Apply postcss-is-pseudo-class only to transformed rules that is | ||
// including `:is() selector starting from `section` element or `:root` | ||
// pseudo-class | ||
applyPostCSSIsPseudoClass(rule, helpers) | ||
} | ||
} | ||
}, | ||
) | ||
|
||
export default nesting |
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
Oops, something went wrong.