Skip to content

Commit

Permalink
fix(preset-attributify): nested attribute parsing (#3275)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris <1633711653@qq.com>
Co-authored-by: Chris <hizyyv@gmail.com>
  • Loading branch information
3 people committed Dec 27, 2023
1 parent dd2bc2f commit a8d0006
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/preset-attributify/src/extractor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Extractor } from '@unocss/core'
import type { Extractor, ExtractorContext } from '@unocss/core'
import { isValidSelector } from '@unocss/core'
import type { AttributifyOptions } from '.'

Expand Down Expand Up @@ -51,6 +51,10 @@ export function extractorAttributify(options?: AttributifyOptions): Extractor {
.split(splitterRE)
.filter(isValidSelector)
}
else if (elementRE.test(content)) {
elementRE.lastIndex = 0
return this.extract!({ code: content } as ExtractorContext) as string[]
}
else {
if (options?.prefixedOnly && options.prefix && !name.startsWith(options.prefix))
return []
Expand Down
1 change: 1 addition & 0 deletions test/cases/preset-attributify/case-5/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
]}
class="text-red"
text="green"
component={<CompName bottom-5 class="absolute" component={<input top-5 />} />}
/>
3 changes: 3 additions & 0 deletions test/cases/preset-attributify/case-5/output.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* layer: default */
.absolute{position:absolute;}
[bottom-5=""]{bottom:1.25rem;}
[top-5=""]{top:1.25rem;}
.text-red{--un-text-opacity:1;color:rgb(248 113 113 / var(--un-text-opacity));}
[text~="green"]{--un-text-opacity:1;color:rgb(74 222 128 / var(--un-text-opacity));}

0 comments on commit a8d0006

Please sign in to comment.