1
0
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:
Bogdan Chadkin
2021-03-10 16:02:37 +03:00
parent 10ac712282
commit c50decb438
9 changed files with 55 additions and 38 deletions

View File

@ -38,17 +38,18 @@ exports.fn = function (ast, options) {
elems.forEach(function (elem) {
if (elem.isElem('style')) {
// <style> element
var styleCss = elem.content[0].text || elem.content[0].cdata || [];
var DATA =
styleCss.indexOf('>') >= 0 || styleCss.indexOf('<') >= 0
? 'cdata'
: 'text';
elem.content[0][DATA] = csso.minify(
styleCss,
minifyOptionsForStylesheet
).css;
if (elem.content[0].type === 'text' || elem.content[0].type === 'cdata') {
const styleCss = elem.content[0].value;
const minified = csso.minify(styleCss, minifyOptionsForStylesheet).css;
// TODO figure out if this check is necessary
if (styleCss.indexOf('>') >= 0 || styleCss.indexOf('<') >= 0) {
elem.content[0].type = 'cdata';
elem.content[0].value = minified;
} else {
elem.content[0].type = 'text';
elem.content[0].value = minified;
}
}
} else {
// style attribute
var elemStyle = elem.attr('style').value;