mirror of
https://github.com/element-hq/element-web.git
synced 2024-11-30 23:31:28 +03:00
Fix line numbers when missing trailing newline
_addLineNumbers expected code blocks to contain a trailing newline, but this is not always the case. Signed-off-by: Robin Townsend <robin@robin.town>
This commit is contained in:
parent
75bfaa58bb
commit
f1a9c5ae93
1 changed files with 3 additions and 3 deletions
|
@ -216,12 +216,12 @@ export default class TextualBody extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
_addLineNumbers(pre) {
|
_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>';
|
pre.innerHTML = '<span class="mx_EventTile_lineNumbers"></span>' + pre.innerHTML + '<span></span>';
|
||||||
const lineNumbers = pre.getElementsByClassName("mx_EventTile_lineNumbers")[0];
|
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)
|
// 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>';
|
lineNumbers.innerHTML += '<span class="mx_EventTile_lineNumber">' + i + '</span>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue