mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
Add mergeStyles plugin (#1381)
This commit is contained in:
@ -189,7 +189,10 @@ function csstreeToStyleDeclaration(declaration) {
|
||||
* @return {string} CSS string or empty array if no styles are set
|
||||
*/
|
||||
function getCssStr(elem) {
|
||||
if (elem.children[0].type === 'text' || elem.children[0].type === 'cdata') {
|
||||
if (
|
||||
elem.children.length > 0 &&
|
||||
(elem.children[0].type === 'text' || elem.children[0].type === 'cdata')
|
||||
) {
|
||||
return elem.children[0].value;
|
||||
}
|
||||
return '';
|
||||
@ -203,10 +206,19 @@ function getCssStr(elem) {
|
||||
* @return {string} reference to field with CSS
|
||||
*/
|
||||
function setCssStr(elem, css) {
|
||||
if (elem.children[0].type === 'text' || elem.children[0].type === 'cdata') {
|
||||
elem.children[0].value = css;
|
||||
return elem.children[0].value;
|
||||
if (elem.children.length === 0) {
|
||||
elem.children.push({
|
||||
type: 'text',
|
||||
value: '',
|
||||
});
|
||||
}
|
||||
|
||||
if (elem.children[0].type !== 'text' && elem.children[0].type !== 'cdata') {
|
||||
return css;
|
||||
}
|
||||
|
||||
elem.children[0].value = css;
|
||||
|
||||
return css;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user