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

Fixes to compatibility of line number and line higlight plugins #1194

Merged
merged 4 commits into from
Dec 5, 2017

Conversation

VitaliyR
Copy link
Contributor

Hello.

First of all, sorry about created compatibility issues with this plugins. But 2 years passed after that PR.. I've just missed this point :)

In this PR:

  • Fixes to line numbers plugin with the different line endings
  • Renamed data-start attribute to data-line-numbers-start - because line highlight plugin is using this attribute as well
  • Fixes compatibility between these two plugins

I've decided to not separate bug fix to into its own branch because it is tied up to each other.

*/
var _resizeElement = function (element) {
var codeStyles = getStyles(element);
var code = element.querySelector('code');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant with codeElement declared a few lines below.

@@ -102,13 +109,37 @@
lineNumbersWrapper.className = 'line-numbers-rows';
lineNumbersWrapper.innerHTML = lines;

if (pre.hasAttribute('data-start')) {
pre.style.counterReset = 'linenumber ' + (parseInt(pre.getAttribute('data-start'), 10) - 1);
if (pre.hasAttribute('data-line-numbers-start')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why you want to rename this data attribute... but it looks quite BC-breaking to me. We would need to update the docs, etc.

I would suggest you do the exact opposite: rename the data attribute used in line-highlight. AFAIK it's only used for the CSS ;)

@Golmote
Copy link
Contributor

Golmote commented Sep 25, 2017

No need to be sorry at all. And a huge thanks for diving into this!

@VitaliyR
Copy link
Contributor Author

@Golmote Thanks! PR fixed. I've revert rename and, also, found that we can even don't rename it at all - anyway if these plugins used together, line highlight won't need data-start attribute at all.

And thanks for showing me that silly mistake, removed it.

@VitaliyR
Copy link
Contributor Author

VitaliyR commented Oct 9, 2017

So, guys, what do you say? Should we wait two years for this one? :D


number = Math.abs(lineNumberStart) + number;

return lineNumberRows.children[number];
Copy link
Contributor

@Golmote Golmote Oct 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VitaliyR I think there is something wrong here. children is zero-indexed, while number (a value from data-line) is one-indexed. I tested in local and the highlighted line is indeed shifted down by one when line-numbers is used.

@VitaliyR
Copy link
Contributor Author

VitaliyR commented Nov 9, 2017

@Golmote thanks for finding! Indeed, I've encountered a bug. So, I've pushed fixes for it, which are also includes other bugfixes related to compatibility issues between this two plugins.

Also, I've created a hook for line-numbers - in the case, when line highlight is loaded before line numbers. It could be if user manually connects <script> tag of line highlight before line numbers, or if the user has downloaded Prism from the website builder, where line numbers are added after line highlight :)

P.S. Sorry for long response

@Golmote
Copy link
Contributor

Golmote commented Nov 11, 2017

P.S. Sorry for long response

I can't blame you, can I? ^^

Is the hook required? Not that I'm particularly against it, but since the plugin already runs in the complete hook and the highlighting occurs when the DOM is ready... do you have a use case where the complete hook can run before both plugins are loaded?

@VitaliyR
Copy link
Contributor Author

@Golmote haha :)
Yes, pay attention at http://prismjs.com/download.html when you're selecting both plugins - line highlight is first in the JS source code textarea. So, it will be loaded & parsed & added to complete hook firstly - before line numbers. So it will ask line numbers plugin for getting line number before the plugin will do the job - and here is a problem.

@Golmote Golmote changed the base branch from master to gh-pages December 5, 2017 19:22
@Golmote Golmote merged commit e63058f into PrismJS:gh-pages Dec 5, 2017
@Golmote
Copy link
Contributor

Golmote commented Dec 5, 2017

Looks good to me! Thanks for working on this!

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.

2 participants