It makes the assumption that the last entry in the array is always an empty string, but in my case that's not true. For me the last entry is "</span>". The slicing ignores that and thereby passes invalid HTML from here on.
Putting the slicing behind a check if the last line really is empty solves the problem for me.
let lines = html.split("\n");
// Trim last line if it is empty
if (lines[lines.length - 1] === "") {
lines = lines.slice(0, -1);
}
I tried reproducing that with the test setup in this repository, but I was unable to do so. I can reproduce the error in a full eleventy setup though.
Noticed on my blog that every
diff
block generates unclosed<span>
-elements.I was able to trace the problem down to this particular line:
https://github.com/11ty/eleventy-plugin-syntaxhighlight/blob/ac92151c42996faef19650f34f54a77e4ac210f2/src/markdownSyntaxHighlightOptions.js#L28
It makes the assumption that the last entry in the array is always an empty string, but in my case that's not true. For me the last entry is
"</span>"
. The slicing ignores that and thereby passes invalid HTML from here on.Putting the slicing behind a check if the last line really is empty solves the problem for me.
I tried reproducing that with the test setup in this repository, but I was unable to do so. I can reproduce the error in a full eleventy setup though.
Git repo where the problem is reproducible: https://github.com/marvinhagemeister/eleventy-diff-syntax-highlight-bug
Steps to reproduce:
npm install
npm run build
dist/foo/index.html
contains invalid HTML