mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
Convert cdata and text nodes to xast
Ref https://github.com/syntax-tree/xast More consistent naming and distinction by type looks a bit cleaner.
This commit is contained in:
@ -189,7 +189,10 @@ function csstreeToStyleDeclaration(declaration) {
|
||||
* @return {string|Array} CSS string or empty array if no styles are set
|
||||
*/
|
||||
function getCssStr(elem) {
|
||||
return elem.content[0].text || elem.content[0].cdata || [];
|
||||
if (elem.content[0].type === 'text' || elem.content[0].type === 'cdata') {
|
||||
return elem.content[0].value;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -200,15 +203,11 @@ function getCssStr(elem) {
|
||||
* @return {Object} reference to field with CSS
|
||||
*/
|
||||
function setCssStr(elem, css) {
|
||||
// in case of cdata field
|
||||
if (elem.content[0].cdata) {
|
||||
elem.content[0].cdata = css;
|
||||
return elem.content[0].cdata;
|
||||
if (elem.content[0].type === 'text' || elem.content[0].type === 'cdata') {
|
||||
elem.content[0].value = css;
|
||||
return elem.content[0].value;
|
||||
}
|
||||
|
||||
// in case of text field + if nothing was set yet
|
||||
elem.content[0].text = css;
|
||||
return elem.content[0].text;
|
||||
return css;
|
||||
}
|
||||
|
||||
module.exports.flattenToSelectors = flattenToSelectors;
|
||||
|
Reference in New Issue
Block a user