Skip to content

Commit 0664aae

Browse files
Fix class detection in markdown code fences and slim templates (#8569)
* Fix detection of classes in markdown code fences * Fix candidate detection in `.slim` templates * Update changelog
1 parent c44dd7b commit 0664aae

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Fix candidate extractor regression ([#8558](https://github.com/tailwindlabs/tailwindcss/pull/8558))
1313
- Split `::backdrop`` into separate defaults group ([#8567](https://github.com/tailwindlabs/tailwindcss/pull/8567))
1414
- Fix postcss plugin type ([#8564](https://github.com/tailwindlabs/tailwindcss/pull/8564))
15+
- Fix class detection in markdown code fences and slim templates ([#8569](https://github.com/tailwindlabs/tailwindcss/pull/8569))
1516

1617
## [3.1.0] - 2022-06-08
1718

src/lib/defaultExtractor.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function* buildRegExps(context) {
2525

2626
let utility = regex.any([
2727
// Arbitrary properties
28-
/\[[^\s:'"]+:[^\s\]]+\]/,
28+
/\[[^\s:'"`]+:[^\s\]]+\]/,
2929

3030
// Utilities
3131
regex.pattern([
@@ -43,7 +43,7 @@ function* buildRegExps(context) {
4343
/(?![{([]])/,
4444

4545
// optionally followed by an opacity modifier
46-
/(?:\/[^\s'"\\><$]*)?/,
46+
/(?:\/[^\s'"`\\><$]*)?/,
4747
]),
4848

4949
regex.pattern([
@@ -54,11 +54,11 @@ function* buildRegExps(context) {
5454
/(?![{([]])/,
5555

5656
// optionally followed by an opacity modifier
57-
/(?:\/[^\s'"\\$]*)?/,
57+
/(?:\/[^\s'"`\\$]*)?/,
5858
]),
5959

6060
// Normal values w/o quotes — may include an opacity modifier
61-
/[-\/][^\s'"\\$={><]*/,
61+
/[-\/][^\s'"`\\$={><]*/,
6262
])
6363
),
6464
]),
@@ -69,8 +69,8 @@ function* buildRegExps(context) {
6969
'((?=((',
7070
regex.any(
7171
[
72-
regex.pattern([/([^\s"'\[\\]+-)?\[[^\s"'\\]+\]/, separator]),
73-
regex.pattern([/[^\s"'\[\\]+/, separator]),
72+
regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s"'`\\]+\]/, separator]),
73+
regex.pattern([/[^\s"'`\[\\]+/, separator]),
7474
],
7575
true
7676
),
@@ -91,7 +91,7 @@ function* buildRegExps(context) {
9191
])
9292

9393
// 5. Inner matches
94-
// yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g
94+
yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g
9595
}
9696

9797
// We want to capture any "special" characters

tests/default-extractor.test.js

+23-4
Original file line numberDiff line numberDiff line change
@@ -415,28 +415,24 @@ test('with single quotes array within template literal', async () => {
415415
const extractions = defaultExtractor(`<div class=\`\${['pr-1.5']}\`></div>`)
416416

417417
expect(extractions).toContain('pr-1.5')
418-
expect(extractions).not.toContain('pr-1')
419418
})
420419

421420
test('with double quotes array within template literal', async () => {
422421
const extractions = defaultExtractor(`<div class=\`\${["pr-1.5"]}\`></div>`)
423422

424423
expect(extractions).toContain('pr-1.5')
425-
expect(extractions).not.toContain('pr-1')
426424
})
427425

428426
test('with single quotes array within function', async () => {
429427
const extractions = defaultExtractor(`document.body.classList.add(['pl-1.5'].join(" "));`)
430428

431429
expect(extractions).toContain('pl-1.5')
432-
expect(extractions).not.toContain('pl-1')
433430
})
434431

435432
test('with double quotes array within function', async () => {
436433
const extractions = defaultExtractor(`document.body.classList.add(["pl-1.5"].join(" "));`)
437434

438435
expect(extractions).toContain('pl-1.5')
439-
expect(extractions).not.toContain('pl-1')
440436
})
441437

442438
test('with angle brackets', async () => {
@@ -449,3 +445,26 @@ test('with angle brackets', async () => {
449445
expect(extractions).not.toContain('>shadow-xl')
450446
expect(extractions).not.toContain('shadow-xl<')
451447
})
448+
449+
test('markdown code fences', async () => {
450+
const extractions = defaultExtractor('<!-- this should work: `.font-bold`, `.font-normal` -->')
451+
452+
expect(extractions).toContain('font-bold')
453+
expect(extractions).toContain('font-normal')
454+
expect(extractions).not.toContain('.font-bold')
455+
expect(extractions).not.toContain('.font-normal')
456+
})
457+
458+
test('classes in slim templates', async () => {
459+
const extractions = defaultExtractor(`
460+
p.bg-red-500.text-sm
461+
'This is a paragraph
462+
small.italic.text-gray-500
463+
'(Look mom, no closing tag!)
464+
`)
465+
466+
expect(extractions).toContain('bg-red-500')
467+
expect(extractions).toContain('text-sm')
468+
expect(extractions).toContain('italic')
469+
expect(extractions).toContain('text-gray-500')
470+
})

0 commit comments

Comments
 (0)