'use strict'; /** * @typedef {import('../lib/types').XastElement} XastElement * @typedef {import('../lib/types').XastChild} XastChild */ const { visitSkip, detachNodeFromParent } = require('../lib/xast.js'); exports.name = 'mergeStyles'; exports.description = 'merge multiple style elements into one'; /** * Merge multiple style elements into one. * * @author strarsis * * @type {import('./plugins-types').Plugin<'mergeStyles'>} */ exports.fn = () => { /** * @type {?XastElement} */ let firstStyleElement = null; let collectedStyles = ''; /** * @type {'text' | 'cdata'} */ let styleContentType = 'text'; return { element: { enter: (node, parentNode) => { // skip content if (node.name === 'foreignObject') { return visitSkip; } // collect style elements if (node.name !== 'style') { return; } // skip