Skip to content
Merged
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
9 changes: 8 additions & 1 deletion plugins/line-highlight/prism-line-highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

var LINE_NUMBERS_CLASS = 'line-numbers';
var LINKABLE_LINE_NUMBERS_CLASS = 'linkable-line-numbers';
var NEW_LINE_EXP = /\n(?!$)/g;

/**
* @param {string} selector
Expand Down Expand Up @@ -136,7 +137,8 @@
var codeElement = pre.querySelector('code');
var parentElement = hasLineNumbers ? pre : codeElement || pre;
var mutateActions = /** @type {(() => void)[]} */ ([]);

var lineBreakMatch = codeElement.textContent.match(NEW_LINE_EXP);
var numberOfLines = lineBreakMatch ? lineBreakMatch.length + 1 : 1;
/**
* The top offset between the content box of the <code> element and the content box of the parent element of
* the line highlight element (either `<pre>` or `<code>`).
Expand All @@ -154,6 +156,11 @@

var start = +range[0];
var end = +range[1] || start;
end = Math.min(numberOfLines, end);

if (end < start) {
return;
}

/** @type {HTMLElement} */
var line = pre.querySelector('.line-highlight[data-range="' + currentRange + '"]') || document.createElement('div');
Expand Down
2 changes: 1 addition & 1 deletion plugins/line-highlight/prism-line-highlight.min.js

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