Skip to content

Investigate better SVG code parsing  #49

@tomayac

Description

@tomayac

Maybe use https://github.com/WebReflection/linkedom for

svg = svg.replace(
'fill="#000000" stroke="none"',
`fill="rgb(${r},${g},${b})" stroke="rgb(${r},${g},${b})"${
a === '255'
? ''
: ` fill-opacity="${alpha}" stroke-opacity="${alpha}"`
} stroke-width="${params.strokeWidth}px"`,
);
const pathRegEx = /<path\s*d="([^"]+)"\/>/g;
let matches;
const shortPaths = [];
while ((matches = pathRegEx.exec(svg)) !== null) {
const path = matches[1];
if (path.split(' ').length < params.minPathSegments) {
shortPaths.push(matches[0]);
}
}
shortPaths.forEach((path) => {
svg = svg.replace(path, '');
});
.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions