update `<style>` patterns

master
Brad Cornes 2021-09-10 12:33:35 +01:00
parent a1e085d0cd
commit 6367de3870
2 changed files with 6 additions and 17 deletions

View File

@ -9,10 +9,7 @@ export interface LanguageBoundaries {
css: Range[]
}
export function getLanguageBoundaries(
state: State,
doc: TextDocument
): LanguageBoundaries | null {
export function getLanguageBoundaries(state: State, doc: TextDocument): LanguageBoundaries | null {
if (isVueDoc(doc)) {
let text = doc.getText()
let blocks = findAll(
@ -23,10 +20,7 @@ export function getLanguageBoundaries(
let cssRanges: Range[] = []
for (let i = 0; i < blocks.length; i++) {
let range = {
start: indexToPosition(
text,
blocks[i].index + blocks[i].groups.open.length
),
start: indexToPosition(text, blocks[i].index + blocks[i].groups.open.length),
end: indexToPosition(
text,
blocks[i].index + blocks[i][0].length - blocks[i].groups.close.length
@ -48,7 +42,7 @@ export function getLanguageBoundaries(
if (isHtmlDoc(state, doc) || isJsDoc(state, doc) || isSvelteDoc(doc)) {
let text = doc.getText()
let styleBlocks = findAll(
/(?<open><style(?:\s[^>]*>|>)).*?(?<close><\/style>|$)/gis,
/(?<open><style(?:\s[^>]*[^\/]>|>|[^\/]>)).*?(?<close><\/style>|$)/gis,
text
)
let htmlRanges: Range[] = []
@ -61,15 +55,10 @@ export function getLanguageBoundaries(
end: indexToPosition(text, styleBlocks[i].index),
})
cssRanges.push({
start: indexToPosition(
text,
styleBlocks[i].index + styleBlocks[i].groups.open.length
),
start: indexToPosition(text, styleBlocks[i].index + styleBlocks[i].groups.open.length),
end: indexToPosition(
text,
styleBlocks[i].index +
styleBlocks[i][0].length -
styleBlocks[i].groups.close.length
styleBlocks[i].index + styleBlocks[i][0].length - styleBlocks[i].groups.close.length
),
})
currentIndex = styleBlocks[i].index + styleBlocks[i][0].length

View File

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