Skip to content

Commit 6367de3

Browse files
committed
update <style> patterns
1 parent a1e085d commit 6367de3

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

packages/tailwindcss-language-service/src/util/getLanguageBoundaries.ts

+5-16
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ export interface LanguageBoundaries {
99
css: Range[]
1010
}
1111

12-
export function getLanguageBoundaries(
13-
state: State,
14-
doc: TextDocument
15-
): LanguageBoundaries | null {
12+
export function getLanguageBoundaries(state: State, doc: TextDocument): LanguageBoundaries | null {
1613
if (isVueDoc(doc)) {
1714
let text = doc.getText()
1815
let blocks = findAll(
@@ -23,10 +20,7 @@ export function getLanguageBoundaries(
2320
let cssRanges: Range[] = []
2421
for (let i = 0; i < blocks.length; i++) {
2522
let range = {
26-
start: indexToPosition(
27-
text,
28-
blocks[i].index + blocks[i].groups.open.length
29-
),
23+
start: indexToPosition(text, blocks[i].index + blocks[i].groups.open.length),
3024
end: indexToPosition(
3125
text,
3226
blocks[i].index + blocks[i][0].length - blocks[i].groups.close.length
@@ -48,7 +42,7 @@ export function getLanguageBoundaries(
4842
if (isHtmlDoc(state, doc) || isJsDoc(state, doc) || isSvelteDoc(doc)) {
4943
let text = doc.getText()
5044
let styleBlocks = findAll(
51-
/(?<open><style(?:\s[^>]*>|>)).*?(?<close><\/style>|$)/gis,
45+
/(?<open><style(?:\s[^>]*[^\/]>|>|[^\/]>)).*?(?<close><\/style>|$)/gis,
5246
text
5347
)
5448
let htmlRanges: Range[] = []
@@ -61,15 +55,10 @@ export function getLanguageBoundaries(
6155
end: indexToPosition(text, styleBlocks[i].index),
6256
})
6357
cssRanges.push({
64-
start: indexToPosition(
65-
text,
66-
styleBlocks[i].index + styleBlocks[i].groups.open.length
67-
),
58+
start: indexToPosition(text, styleBlocks[i].index + styleBlocks[i].groups.open.length),
6859
end: indexToPosition(
6960
text,
70-
styleBlocks[i].index +
71-
styleBlocks[i][0].length -
72-
styleBlocks[i].groups.close.length
61+
styleBlocks[i].index + styleBlocks[i][0].length - styleBlocks[i].groups.close.length
7362
),
7463
})
7564
currentIndex = styleBlocks[i].index + styleBlocks[i][0].length

packages/tailwindcss-language-service/src/util/html.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function isInsideTag(str: string, tag: string | string[]): boolean {
4444
let close = 0
4545
let match: RegExpExecArray
4646
let tags = Array.isArray(tag) ? tag : [tag]
47-
let regex = new RegExp(`<(?<slash>/?)(?:${tags.join('|')})\\b`, 'ig')
47+
let regex = new RegExp(`<(?<slash>/?)(?:${tags.join('|')})(?:\\s[^>]*[^\/]>|>|[^\/]>)`, 'ig')
4848
while ((match = regex.exec(str)) !== null) {
4949
if (match.groups.slash) {
5050
close += 1

0 commit comments

Comments
 (0)