Closed rmcginty closed 2 years ago
I've managed to recreate this issue by using either alwaysWrapLineHighlights: true
or lineSeparator: "\r\n"
as options.
I don't think the issue is with Prism. I think the issue is with the way we're splitting lines here: https://github.com/11ty/eleventy-plugin-syntaxhighlight/blob/e992469c4fd3e910e1dab3865f0e23ee481ea8b9/src/HighlightPairedShortcode.js#L23-L32
By only splitting on '\n' we're leaving a carriage return in the string. For example:
'foo\r\nbar'.split('\n') --> ['foo\r', 'bar']
Then when we're joining with the line separator we're getting:
['foo\r', 'bar'].join('<br>') --> 'foo\r<br>bar'
Hmm. I am using alwaysWrapLineHighlights: false
and lineSeparator: '<br>'
and still see the issue. I was able to get the unit tests running. Let me see if I can get a couple of new tests that reproduce the issue.
Those waiting on the above-linked PR can apply this patch (which contains a bunch of irrelevant auto-formatting changes, sorry):
` + lines.join(options.lineSeparator || "
") + "
";
+ return `${lines.join(options.lineSeparator || "
")}
`;
};
```
Shipping with 4.1.0!
This works fine in Markdown, but in Nunjucks, having \r\n at the end of a line results in two blank lines. Apparently Prism is outputting multiple \n instead of preserving the line ending which results in the Nunjucks template code adding an extra blank line for each line in the input.
Solution seems to be to remove all \r prior to highlighting. Submitting a PR.