Merge pull request #5800 from robintown/fix-line-numbers

Fix line numbers when missing trailing newline
This commit is contained in:
Travis Ralston 2021-03-25 19:04:23 -06:00 committed by GitHub
commit 8a33f8cfc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -216,12 +216,12 @@ export default class TextualBody extends React.Component {
}
_addLineNumbers(pre) {
// Calculate number of lines in pre
const number = pre.innerHTML.replace(/\n(<\/code>)?$/, "").split(/\n/).length;
pre.innerHTML = '<span class="mx_EventTile_lineNumbers"></span>' + pre.innerHTML + '<span></span>';
const lineNumbers = pre.getElementsByClassName("mx_EventTile_lineNumbers")[0];
// Calculate number of lines in pre
const number = pre.innerHTML.split(/\n/).length;
// Iterate through lines starting with 1 (number of the first line is 1)
for (let i = 1; i < number; i++) {
for (let i = 1; i <= number; i++) {
lineNumbers.innerHTML += '<span class="mx_EventTile_lineNumber">' + i + '</span>';
}
}