Skip to content

Commit

Permalink
fix(preset-typography): escape selector in typography (#819)
Browse files Browse the repository at this point in the history
  • Loading branch information
ydcjeff committed May 7, 2022
1 parent 1d52e8f commit 634847a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
3 changes: 1 addition & 2 deletions packages/preset-typography/README.md
Expand Up @@ -12,8 +12,7 @@ pnpm add @unocss/preset-typography -D

```js
// unocss.config.js
import { defineConfig, presetAttributify, presetUno } from 'unocss'
import { presetTypography } from '@unocss/preset-typography'
import { defineConfig, presetAttributify, presetTypography, presetUno } from 'unocss'

export default defineConfig({
presets: [
Expand Down
6 changes: 3 additions & 3 deletions packages/preset-typography/src/index.ts
@@ -1,5 +1,6 @@
import type { CSSObject, Preset, RuleContext } from '@unocss/core'
import type { Theme } from '@unocss/preset-mini'
import { toEscapedSelector } from '@unocss/core'
import { getPreflights } from './preflights'

/**
Expand Down Expand Up @@ -30,8 +31,7 @@ export interface TypographyOptions {
*
* ```js
* // unocss.config.js
* import { presetAttributify, presetUno, defineConfig } from 'unocss'
* import { presetTypography } from '@unocss/preset-typography'
* import { presetAttributify, presetUno, defineConfig, presetTypography } from 'unocss'
*
* export default defineConfig({
* presets: [
Expand Down Expand Up @@ -63,7 +63,7 @@ export function presetTypography(options?: TypographyOptions): Preset {
classNameRE,
(_, { rawSelector }) => {
hasProseClass = true
selectorProse = rawSelector
selectorProse = toEscapedSelector(rawSelector)
return { 'color': 'var(--un-prose-body)', 'max-width': '65ch' }
},
{ layer: 'typography' },
Expand Down
6 changes: 3 additions & 3 deletions packages/preset-typography/src/preflights/index.ts
Expand Up @@ -57,9 +57,9 @@ export function getPreflights(
className: string,
cssExtend?: object | undefined,
): string {
// attribute selector
if (!selectorProse.startsWith('['))
selectorProse = `.${selectorProse}`
// attribute mode -> add class selector with `:is()` pseudo-class function
if (!selectorProse.startsWith('.'))
selectorProse = `:is(${selectorProse},.${className})`

if (cssExtend)
return getCSS(selectorProse, className, mergeDeep(DEFAULT, cssExtend))
Expand Down

0 comments on commit 634847a

Please sign in to comment.