mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-21 17:26:29 -05:00
fix: use more complex parsing for css statement splitting
Signed-off-by: Lim Jia Sheng <50891910+sxxov@users.noreply.github.com>
This commit is contained in:
parent
e7d81c5cdf
commit
620b7d9fa8
1 changed files with 31 additions and 4 deletions
|
@ -17,9 +17,34 @@ export function convertInlineStyleToMap(
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
return inlineStyle
|
const statements: string[] = []
|
||||||
.split(';')
|
let i = -1
|
||||||
.reduce<Record<string, string>>((styleObject, stylePropertyValue) => {
|
let offset = 0
|
||||||
|
do {
|
||||||
|
i++
|
||||||
|
let curr = inlineStyle[i]
|
||||||
|
let prev = inlineStyle[i - 1]
|
||||||
|
|
||||||
|
if ((curr === "'" || curr === '"') && prev !== '\\') {
|
||||||
|
const quote = curr
|
||||||
|
do {
|
||||||
|
i++
|
||||||
|
curr = inlineStyle[i]
|
||||||
|
prev = inlineStyle[i - 1]
|
||||||
|
} while (!(curr === quote && prev !== '\\') && i < inlineStyle.length)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curr === ';' && prev !== '\\') {
|
||||||
|
statements.push(inlineStyle.slice(offset, i))
|
||||||
|
offset = i + 1
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} while (i < inlineStyle.length)
|
||||||
|
statements.push(inlineStyle.slice(offset, inlineStyle.length))
|
||||||
|
|
||||||
|
return statements.reduce<Record<string, string>>(
|
||||||
|
(styleObject, stylePropertyValue) => {
|
||||||
// extract the style property name and value
|
// extract the style property name and value
|
||||||
const [property, value] = stylePropertyValue
|
const [property, value] = stylePropertyValue
|
||||||
.split(/^([^:]+):/)
|
.split(/^([^:]+):/)
|
||||||
|
@ -45,5 +70,7 @@ export function convertInlineStyleToMap(
|
||||||
styleObject[replacedProperty] = value
|
styleObject[replacedProperty] = value
|
||||||
|
|
||||||
return styleObject
|
return styleObject
|
||||||
}, {})
|
},
|
||||||
|
{}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue