mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-22 17:21:34 +00: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 inlineStyle
|
||||
.split(';')
|
||||
.reduce<Record<string, string>>((styleObject, stylePropertyValue) => {
|
||||
const statements: string[] = []
|
||||
let i = -1
|
||||
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
|
||||
const [property, value] = stylePropertyValue
|
||||
.split(/^([^:]+):/)
|
||||
|
@ -45,5 +70,7 @@ export function convertInlineStyleToMap(
|
|||
styleObject[replacedProperty] = value
|
||||
|
||||
return styleObject
|
||||
}, {})
|
||||
},
|
||||
{}
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue