Skip to content
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

Ignore single-line highlight which is out of wrap section #3475

Merged
merged 3 commits into from Jun 16, 2022

Conversation

lijyze
Copy link
Contributor

@lijyze lijyze commented Jun 15, 2022

When highlight a range, if its end line exceed the wrap section, prism highlight from start line of the rang to the end of wrap section. That's good.
When thing comes to a single line, prism highlight the last line of wrap section, that's weird.

So ,I make it a little different, if the single-line is out of wrap section, simply ignore this line.

@github-actions
Copy link

github-actions bot commented Jun 15, 2022

JS File Size Changes (gzipped)

A total of 1 files have changed, with a combined diff of +51 B (+3.5%).

file master pull size diff % diff
plugins/line-highlight/prism-line-highlight.min.js 1.47 KB 1.52 KB +51 B +3.5%

Generated by 🚫 dangerJS against 0240cd6

@lijyze lijyze changed the title Ignore single-line highlight which is out of range Ignore single-line highlight which is out of wrap section Jun 15, 2022
@RunDevelopment
Copy link
Member

Thank you for the PR @lijyze!

Unfortunately, I do not understand the problem you fixed. Could you please explain it in more detail? Maybe even provide some screenshots?

@lijyze
Copy link
Contributor Author

lijyze commented Jun 15, 2022

@RunDevelopment Sorry for bad explanation.

Let's say, if my code looks like this, it has only 3 lines of code.
image

Now I want highlight some lines of it.

  • If the end line of range exceed max line numbers of code, such as data-line="2-10"
    • Without class="line-numbers":
      image
    • And with class="line-numbers":
      image

I think this make sense, it means highlight from the start of the range to the end of the code.
But if the section is exceeded by a line rather than a range, things comes a little weird.

  • Code section exceed by a line, such as data-line="4"
    • Without class="line-numbers":
      image
      This could be hidden as required.
    • With class="line-numbers":
      image
      It display incorrectly in some ways, and there seems no way to post-process it.

What have I done is ignore lines that exceed line numbers of code section when class="line-number" is present.

Thank you for reading this, I wish you a good day!

@RunDevelopment
Copy link
Member

Thank you for the detailed explanation!

Instead of working around the different behavior of with and without class="line-number", why don't we fix the underlying problem? The real problem is that the range is invalid. If the start and end of the range were inside the code block, we wouldn't have this issue in the first place.

So we could count the number of lines (once) and then do end = Math.min(numberOfLines, end). What do you think about this approach?

@RunDevelopment
Copy link
Member

Similarly, we could also ignore (= not display) any ranges or single-lines if their start is greater than the number of lines.

@lijyze
Copy link
Contributor Author

lijyze commented Jun 16, 2022

Yeah! Your solution is much more elegant.
Thanks you for giving pointer!!! I have done with code!

@RunDevelopment RunDevelopment merged commit 9a4e725 into PrismJS:master Jun 16, 2022
@RunDevelopment
Copy link
Member

Thank you for contributing @lijyze!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants