Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special characters generate weird CDATA tag? #58

Closed
OfficialCRUGG opened this issue Jul 14, 2023 · 4 comments
Closed

Special characters generate weird CDATA tag? #58

OfficialCRUGG opened this issue Jul 14, 2023 · 4 comments

Comments

@OfficialCRUGG
Copy link

Hey there!

I am currently trying to use svgson to do some bulk operations on some icons.

The source SVG includes <title>Aerom&#233;xico</title>, but when running this through svgson, it returns <title><![CDATA[Aerom&#233;xico]]></title> which causes further issues due to not being a valid HTML tag.

Is there any way to fix this?

@elrumordelaluz
Copy link
Owner

Hi @OfficialCRUGG, thanks for open the Issue.

You have to make use of transformNode option of stringify, which allow you to transform each node. In this case, you want to decode html entities. I presume you are in a nodejs env (and not browser), so you have to do it with something like this lib.

Here is an example of transformNode function:

function transformNode(node) {
  return {
    ...node,
    ...(node.children ? { children: node.children.map(transformNode) } : {}),
    value: entities.decodeHTML(node.value),
  };
}

and here is a working example.

@OfficialCRUGG
Copy link
Author

There doesn't seem to be any tramsformNode option in the type definitions, @elrumordelaluz?

image

@elrumordelaluz
Copy link
Owner

elrumordelaluz commented Jul 18, 2023

what svgson version are you using? Thanks to your issue I found that this prop wasn't included in types. can you please update in case?

@OfficialCRUGG
Copy link
Author

Updated from 5.3.0 to 5.3.1 and that solved it. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants