Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugins/line-numbers/prism-line-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@

codeLines.forEach(function (line, lineNumber) {
lineNumberSizer.textContent = line || '\n';
var lineSize = lineNumberSizer.getBoundingClientRect().height;
lineNumbersWrapper.children[lineNumber].style.height = lineSize + 'px';
var lineSize = getComputedStyle(lineNumberSizer).lineHeight;
Copy link
Member

Choose a reason for hiding this comment

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

Can we assume that getComputedStyle(lineNumberSizer).lineHeight is equivalent to lineNumberSizer.getBoundingClientRect().height + 'px'? Especially cross browser?

(Line Numbers is one of our most-used plugins, so I don't want to break websites just because this change seems sound.)

Copy link
Contributor Author

@lynette-li lynette-li May 7, 2020

Choose a reason for hiding this comment

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

How about we set lineSize to be lineNumberSizer.getBoundingClientRect().height + 'px' by default?Only when lineNumberSizer.getBoundingClientRect().height equals 0 will we set it to getComputedStyle(lineNumberSizer).lineHeight.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@RunDevelopment Request for your comments. :)

Copy link
Member

Choose a reason for hiding this comment

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

(Thanks for the reminder)

I tested your solution (without fallback) and it doesn't work with soft wrap.

Details

Screenshot from 2020-05-11 15-04-12

Should be:

Screenshot from 2020-05-11 15-13-23

I don't think there's a lot we can do to fix this. The browser needs to break and wrap the text for us.

lineNumbersWrapper.children[lineNumber].style.height = lineSize;
});

lineNumberSizer.textContent = '';
Expand Down
2 changes: 1 addition & 1 deletion plugins/line-numbers/prism-line-numbers.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.