SVGR exception with CDATA inside <style/> tag
See original GitHub issueHello!
My application to design SVG uses CDATA inside the <style/> section. All tested browsers open this SVG without issues:
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="960px" height="560px" version="1.1" viewBox="0 0 960 560">
<defs>
<style type="text/css">
<![CDATA[
.fnt0 {font-weight:normal;font-size:39px;font-family:'Arial'}
]]>
</style>
</defs>
<g id="XO">
<metadata id="Layer"/>
<text x="751" y="104" id="Temp" class="fnt0">25.0°C</text>
</g>
</svg>
But SVGR fails to convert the SVG if i disable SVGO:
PS src\application\components> npx @svgr/cli --icon --no-svgo -d .\ .\svg\cdata.svg
node_modules\@svgr\cli\lib\index.js:162
throw error;
^
Error: Expected node, got `
.fnt0 {font-weight:normal;font-size:39px;font-family:'Arial'}
`
at one (node_modules\@svgr\cli\node_modules\@svgr\hast-util-to-babel-ast\lib\one.js:12:11)
at all (node_modules\@svgr\cli\node_modules\@svgr\hast-util-to-babel-ast\lib\all.js:20:37)
at element (node_modules\@svgr\cli\node_modules\@svgr\hast-util-to-babel-ast\lib\handlers.js:51:37)
at one (node_modules\@svgr\cli\node_modules\@svgr\hast-util-to-babel-ast\lib\one.js:19:10)
at all (node_modules\@svgr\cli\node_modules\@svgr\hast-util-to-babel-ast\lib\all.js:20:37)
at element (node_modules\@svgr\cli\node_modules\@svgr\hast-util-to-babel-ast\lib\handlers.js:51:37)
at one (node_modules\@svgr\cli\node_modules\@svgr\hast-util-to-babel-ast\lib\one.js:19:10)
at all (node_modules\@svgr\cli\node_modules\@svgr\hast-util-to-babel-ast\lib\all.js:20:37)
at element (node_modules\@svgr\cli\node_modules\@svgr\hast-util-to-babel-ast\lib\handlers.js:51:37)
at one (node_modules\@svgr\cli\node_modules\@svgr\hast-util-to-babel-ast\lib\one.js:19:10)
PS src\application\components>
So maybe SVGO parses the CDATA section without issues but if SVGR parses the SVG directly it fails.
If i simply remove <![CDATA[`` and
]]` SVGO and SVGR have no issues.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Is CDATA necessary when styling an inline SVG?
In theory CDATA blocks are required anywhere you'd want to write unescaped text. In XML, only 2 characters need escaping: < and &...
Read more >Styling – SVG 1.1 (Second Edition) - W3C
CSS style sheets defined within a 'style' element can be immediate character data content of the 'style' element or can be embedded within...
Read more >where to put css code : svg cdata style (inline) and html style ...
IF i use SVG and define css code inside svg using <svg ><style type="text/css" > <![CDATA[ circle ... I use definition css code...
Read more >how to get xsl:copy-of to appear within CDATA - SSDN
RuntimeException : Er... (2) ... xsl report, with xml feed, SVG... (7) ... Marge node using attribute val... (1).
Read more >A Roadmap to XML Parsers in Python - Real Python
[CDATA[ console.log("CDATA disables XML parsing: <svg>") const smiley ... and closing tags of elements using .findtext() or get the inner text of the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Is it possible for this issue to be looked into? Ran into this when upgrading to CRA5