Nuxt amp example: should not remove all script tags
[issue link]Hi,
I’m testing nuxt for an Amp site. Everything is working perfectly (thanks ❤️ ) except one tiny thing.
In the examples you gave
// Remove every script tag from generated HTML
html = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
All scripts tags are removed without consideration, but the solution it not good because amp does allow <script type="application/json"></script>
(in amp-analytics for example)
It’s not really a bug but it can be confusing for newcomers if they simply copy the code 😃
Because I’m not a regex master, I didn’t succeed in modifying the regex to only match script tags that does not have that type (screw you negative lookahead). So I’v done this (which is absolutely not bulletproof but a quick fix)
html = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, (str) => {
if (/application\/json/.test(str)) {
return str;
}
return '';
});
If someone have a better fix 👍
thanks