posthtml / posthtml

PostHTML is a tool to transform HTML/XML with JS plugins

Home Page:https://posthtml.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can not parse html with tags inside script string

hqjs opened this issue · comments

commented

Details

Posthtml can not successfully parse valid html like this

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        window.onerror = function() {
            document.open();
            document.write("<h1>An error occurred</h1>");
            document.close();
        }
    </script>
</head>
<body>
</body>
</html>

It recognizes script content as

window.onerror = function() {
document.open();
document.write("

because of the tag <h1> presented inside the string in a script.

Environment

OS: MacOS Mojave
node: v10.9.0
npm: 6.2.0
package: posthtml@0.11.3

Hi @hqjs ! I just add the script ( just to test it ) on my on going project which is using posthtml, postcss, gulp , sugarss & AMP. It parsed the script as it is without error,

I am using Linux : zorin OS, Node: 8.12

commented

Hi @Mr-Manna, thanks for your help! It seems like node.content is an array of strings split around the tags, so there is no issue here indeed. The whole content might be obtained by joining this array node.content.join().