Skip to content

Commit f7e2082

Browse files
committed
fix(module): safelist regex when a : was present before color
Also prevents parsing colors already safelisted initially.
1 parent f719111 commit f7e2082

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/colors.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,18 @@ export const generateSafelist = (colors: string[]) => {
139139
]
140140
}
141141

142-
export const customSafelistExtractor = (prefix, content: string, colors: string[]) => {
142+
export const customSafelistExtractor = (prefix, content: string, colors: string[], safelistColors: string[]) => {
143143
const classes = []
144-
const regex = /<(\w+)\s+[^>:]*color=["']([^"']+)["'][^>]*>/gs
144+
const regex = /<(\w+)\s+(?![^>]*:color\b)[^>]*\bcolor=["']([^"']+)["'][^>]*>/gs
145+
145146
const matches = content.matchAll(regex)
146147

147148
const components = Object.keys(safelistByComponent).map(component => `${prefix}${component.charAt(0).toUpperCase() + component.slice(1)}`)
148149

149150
for (const match of matches) {
150151
const [, component, color] = match
151152

152-
if (!colors.includes(color)) {
153+
if (!colors.includes(color) || safelistColors.includes(color)) {
153154
continue
154155
}
155156

src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export default defineNuxtModule<ModuleOptions>({
156156
vue: (content) => {
157157
return [
158158
...defaultExtractor(content),
159-
...customSafelistExtractor(options.prefix, content, nuxt.options.appConfig.ui.colors)
159+
...customSafelistExtractor(options.prefix, content, nuxt.options.appConfig.ui.colors, options.safelistColors)
160160
]
161161
}
162162
}

0 commit comments

Comments
 (0)