node-html-parser icon indicating copy to clipboard operation
node-html-parser copied to clipboard

BUG: outerHTML drop <script>'s start tag

Open Zhang-Junzhi opened this issue 1 year ago • 1 comments

<!DOCTYPE html
><html lang="en"
><meta charset="UTF-8"
><title aria-live="polite">test</title
><link href="/style/app" rel="stylesheet"
><link rel="icon" href="/image/logo"><script src="/script/app" type="module"></script

></html>

Parse the above and then retrieve the document text from outerHTML. The <script> will be dropped, making the end </script> tag immediately follow <link>:

<link rel="icon" href="/image/logo"></script

Zhang-Junzhi avatar Apr 11 '24 17:04 Zhang-Junzhi

The result is caused by close tag. you may try this:

const html = `<!DOCTYPE html
><html lang="en"
><meta charset="UTF-8"
><title aria-live="polite">test</title
><link href="/style/app" rel="stylesheet"
><link rel="icon" href="/image/logo"><script src="/script/app" type="module"></script

></html>`.replace(/\n*>/g, '>');
		const root = parse(html);

taoqf avatar May 14 '24 08:05 taoqf