-
-
Notifications
You must be signed in to change notification settings - Fork 298
wrapLongLines + line numbering with wrapped lines #309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This preserves accurate line numbering
3 tasks
karlhorky
reviewed
Sep 13, 2020
karlhorky
reviewed
Sep 13, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #235 and introduces a few API & styling changes along the way.
wrapLongLines
showInlineLineNumbers = true
<code>
tag1. New prop: "wrapLongLines"
wrapLongLines
takes care of addingwhite-space: pre-wrap
styling to the<code>
tag: no need to do this yourself via CSS orcodeTagProps
anymore.There are a few potential consequences of this new prop.
Containing elements around each line
If you've set
wrapLongLines={true}
, React Syntax Highlighter will wrap each line of code in its own<span>
, just as if you'd explicitly setwrapLines={true}
.This could be a breaking change for anyone who is currently:
white-space: pre-wrap
on their<code>
elementwrapLines={false}
or is using Prism, which defaults to not creating containing elements around each line's elementsdisplay: flex to provide long-line wrapping that doesn't flow into the line number area
If you're using
wrapLongLines={true}
and are showing line numbers (showLineNumbers={true}
), we'll now style each line element withdisplay: flex
.This overrides the
display: block
styling that most themes apply to each line.Probably won't be a noticeable change for most users, but if you see any unexpected
line-height
changes with this change, that's probably the cause.2. New default prop value (potentially breaking change)
showInlineLineNumbers = true
The old default for line numbering (
showLineNumbers
+showInlineLineNumbers = false
) created a separate<code>
element containing all line numbers.This was problematic when using a virtualized renderer or when applying
white-space: pre-wrap
to the code area. Since having line numbers inside each line element is advantageous in several cases, I think it should become the default method of rendering line numbers.3. Explicit white-space styling on
<code>
tag (potentially breaking change)In order to set
white-space: pre-wrap
whenwrapLongLines={true}
, RSH now explicitly setswhite-space: pre
when in the default state ofwrapLongLines={false}
. If you've manually appliedwhite-space: pre-wrap
viacodeTagProps
or your theme CSS, this might override your intended styling.The workaround here is to migrate to using the new
wrapLongLines={true}
prop, which will provide thepre-wrap
styling for you.