b-fuze / deno-dom

Browser DOM & HTML parser in Deno
https://jsr.io/@b-fuze/deno-dom
MIT License
425 stars 47 forks source link

Weird space is added when `document.body.outerHTML` #156

Closed BlackAsLight closed 10 months ago

BlackAsLight commented 11 months ago

Give this HTML which is the default format my IDE gives the html document

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="module" src="/js/main.min.js"></script>
</head>

<body>
    <h1>Hello World</h1>
</body>

</html>

It gets a weird format when stringifying the file as '<!DOCTYPE html>\n' + doc.documentElement!.outerHTML

<!DOCTYPE html>
<html lang="en"><head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="module" src="/js/main.min.js"></script>
</head>

<body>
    <h1>Hello World</h1>

</body></html>

It works fine if there was no extra spacing anywhere, like if the file was minified before being parsed.

It would be much more appreciated if whatever output it did give was consistent, where the input format was irrelevant to the output format.

b-fuze commented 10 months ago

This is due to deno-dom using a standards-compliant parser among other things. You can view the same output when you run it through a browser image

BlackAsLight commented 10 months ago

That's unfortunate, but I guess its not a bug...