Yoast / YoastSEO.js

Analyze content on a page and give SEO feedback as well as render a snippet preview.
GNU General Public License v3.0
403 stars 171 forks source link

Generating tree structures for HTML with a comment inside a heading or paragraph fails. #2178

Open hansjovis opened 5 years ago

hansjovis commented 5 years ago

Generating the tree structure fails for HTML that has a comment within a header or paragraph:

<h1>Hello World!<!-- How are you? --></h1>

The comment gets added to the header as a formatting element, as it should be, but something goes wrong when converting the comment from an Ignored node to a FormattingElement.

It currently errors on the calculation of the start- and end position of the formatting elements. Specifically on this line, where it fails to get the start tag. https://github.com/Yoast/YoastSEO.js/blob/545ce68d58bbc4df23e340653532fccab5381da5/src/tree/builder/cleanup/calculateTextIndices.js#L116

More importantly, parse5 recognizes How are you? in the example below as a comment:

<h1>Hello World!</ How are you?