Fix bug with wrapLines that butchers highlighting
#561
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Problem
When highlighting in JSX or TSX and using
prism, template strings would sometimes fail to be highlighted correctly, as seen in the demo screenshot below.To reproduce, include any JSX node with multi-line text as well as a multi-line template string. You'll see that everything between the first and last lines of the template string is highlighted as
plaintextinstead ofstring.This happens even though the demo for the underlying
refractorpackage does not produce such an error.The Cause
The code for
createLineElementinhighlight.jsmodified thelinePropsvariable directly without copying it. This leads tolinePropsat times taking on the className value of the currently processed line, which can then lead to other lines being wrapped with those classes.What happened in the example above is that when the plaintext inside the JSX is processed,
linePropsis butchered and then overrides the previously emittedstringclasses for the template string.This code also leads to odd behavior when
linePropsis specified butwrapLinesis not, with only some lines being affected bylinePropsand others not, seemingly at random.The Fix
linePropsobject to prevent it from being butchered.linePropsobject whenwrapLinesis set to true, as otherwise (according to the README documentation) it has no effect.classNamefield oflinePropswith the generated classes to ensure both are present in the final output.Testing
I have confirmed this fixes the issue above, while also preserving
wrapLinesfunctionality. Additionally,linePropsnow has no effect on output whenwrapLinesis not specified.