Closed sergey-pimenov closed 5 years ago
The issue seems to come from https://github.com/fb55/htmlparser2
I added a --xml
option, could you try to see if you get the output you expect when passing it please?
Thanks!
I try to repeate compile with your fix and unfortunately it's not work for me.
This:
<html>
<head>
<title data-t data-t-interpolate>{{main.chapter}} 1</title>
<script src="js/app.js"></script>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 68 65">
<path d="M14 27v-20c0-3.7-3.3-7-7-7s-7 3.3-7 7v41c0 8.2 9.2 17 20 17s20-9.2 20-20c0-13.3-13.4-21.8-26-18zm6 25c-3.9 0-7-3.1-7-7s3.1-7 7-7 7 3.1 7 7-3.1 7-7 7z"/>
</svg>
</body>
</html>
Compile to:
<html>
<head>
<title>chapter 1</title>
<script src="js/app.js"></script>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 68 65">
<path d="M14 27v-20c0-3.7-3.3-7-7-7s-7 3.3-7 7v41c0 8.2 9.2 17 20 17s20-9.2 20-20c0-13.3-13.4-21.8-26-18zm6 25c-3.9 0-7-3.1-7-7s3.1-7 7-7 7 3.1 7 7-3.1 7-7 7z">
</svg>
</body>
</html>
I'm not familiar with the syntax npm-scripts (before I used gulp plugin) so i tried several variants:
As I understand the first or second variant is correct, but I tried other varians too. Am I doing something wrong?
Also i try to change default settings in your tool (file: static-i18n.js):
default: {
useAttr: true,
fixPaths: true,
replace: false,
removeAttr: true,
xml: true // Change this
}
But this also didn't help.
Thank you for the detailed report. Sorry, it was my mistake. It should now be fixed, please try to upgrade to the newest version.
Great job, thank you very much for your attention! Now everything works fine. Do I understand correctly that Gulp and Grunt plugins automatically will use latest version of node-static-i18n?
Unfortunately, the problem is not solved with Fix bug with xmlmode. As @tuvistavie has already written, the issue comes from htmlparser2.
There are already numerous open issues, for example:
... and possibly a solution that has not yet been merged:
In short: Inline SVG should always be parsed with the XML option enabled even if the option is disabled for the rest of the HTML page.
It's an issue with the dom-serializer that is used in cheeriojs module which is used in static-i18n to parse/modify DOM of the html source files.
I was able to fix this issue by forcing xml mode on svg tag children.
Please see my PR for more details. Not sure if it will be merged, but it's worth a shot.
I was not able to override module deps. using lock file, but as for temporary solution you can patch faulty module and hot-swap using local mock.
require('mock-require')('dom-serializer', require('./vendor/dom-serializer'));
While --xml
does fix the SVG tags, it also causes script tags to be self closing, which doesn't work and therefore causes my site to not render properly. Any thoughts? I need to have script tags since I'm using this for an AMP website, which requires script
tags in the document.
@osdiab I think the workaround proposed by @connected is the best shot for now. Let's hope the PR gets merge.
I think this issue can be closed because it has been fixed since static-i18n updated cheerio dependency to v0.22.0.
Be careful with the gulp package though, it (v0.3.0) still uses the old static-i18n version which has this SVG bug.
Hi! This tool awesome, but I found strange bug: SVG elements like path lose closing '/' after compilation. This problem also exist in gulp plugin.
Example.
This code:
Will compiled to:
Link to example
It's not valid HTML and so it can cause some errors in browsers. It would be great if it's fixed.