Skip to content

Commit

Permalink
fix(windicss): extractor for custom syntax
Browse files Browse the repository at this point in the history
close #503
  • Loading branch information
antfu committed Jun 23, 2021
1 parent 39c1f79 commit 0dd1e0b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@vitejs/plugin-vue": "^1.2.3",
"@vue/composition-api": "^1.0.0-rc.12",
"@vueuse/integrations": "^5.0.3",
"@windicss/plugin-utils": "^1.1.0",
"clear-module": "^4.1.1",
"clipboard": "^2.0.8",
"color": "^3.1.3",
Expand Down
19 changes: 19 additions & 0 deletions src/defaultTheme/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Module, NuxtOptions } from '@nuxt/types'
import gracefulFs from 'graceful-fs'
import clearModule from 'clear-module'
import jiti from 'jiti'
import { DefaultExtractor } from '@windicss/plugin-utils'
import defaultWindiConfig from './windi.config'

const r = (...args: string[]) => resolve(__dirname, ...args)
Expand Down Expand Up @@ -99,6 +100,24 @@ export default <Module>function themeSetupModule() {
detect: [...vueFiles, ...mdFiles]
}

// extract custom markdown syntax, #503
windiOptions.scanOptions.extractors.push({
extensions: ['md'],
extractor(code, id) {
const data = DefaultExtractor(code, id)

const classes = new Set(data.classes)
classes.forEach(i => {
if (i.startsWith('.')) classes.add(i.slice(1))
})

return {
...data,
classes: Array.from(classes)
}
}
})

// Push every included path into scan options
windiOptions.scanOptions.include.push(
join(contentDir, windiGlob),
Expand Down
18 changes: 18 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@
resolved "https://registry.yarnpkg.com/@antfu/utils/-/utils-0.1.7.tgz#ac9e0e62a2490db987c9d8c6b4f38076d763c27f"
integrity sha512-XbmXbhrjfxQq+ishOKeUIK1VYxQV0B+ZkAQkz00bxhmQd5izdT0YRSDwkyH/KX46gFVBMd+6anvSDlciUt3L4A==

"@antfu/utils@^0.2.2":
version "0.2.2"
resolved "https://registry.yarnpkg.com/@antfu/utils/-/utils-0.2.2.tgz#b74c5b6f6de64f7e47a669deba054790b26f85d8"
integrity sha512-8GwVE0j48SpZaLxsHO0BSO0sEpkb+EhFQcABFBFomH4O8AwNVVvGQNRCBKOPUwU4Vxj3ZSVz8PDjUrPGwaYP9A==

"@babel/[email protected]":
version "7.12.11"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f"
Expand Down Expand Up @@ -2875,6 +2880,19 @@
micromatch "^4.0.4"
windicss "^3.1.3"

"@windicss/plugin-utils@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@windicss/plugin-utils/-/plugin-utils-1.1.0.tgz#c0834165f40142bf52f24eced1bbf68cbf8bd506"
integrity sha512-v9WhtcGKRehsbY2Omd9m+Jd0IsjbKJmRSa712BuPLZ+fZuCSomne9twjqtPn29IGqS6T/9lM8aOjW7mRMU1x/g==
dependencies:
"@antfu/utils" "^0.2.2"
debug "^4.3.2"
fast-glob "^3.2.5"
jiti "^1.10.1"
magic-string "^0.25.7"
micromatch "^4.0.4"
windicss "^3.1.3"

"@xtuc/ieee754@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@xtuc/ieee754/-/ieee754-1.2.0.tgz#eef014a3145ae477a1cbc00cd1e552336dceb790"
Expand Down

0 comments on commit 0dd1e0b

Please sign in to comment.