GitHub-userscripts icon indicating copy to clipboard operation
GitHub-userscripts copied to clipboard

(GitHub Collapse In Comment) `numberOfLines` appears to be +1 (it takes `</code>` as line)

Open darkred opened this issue 4 years ago • 0 comments

I've noticed in 'GitHub Collapse In Comment' that the lines count value appears to be +1 the expected one.

The relevant line in the script: https://github.com/Mottie/GitHub-userscripts/blob/af1d51d243ee22773606516c8592f82ebc89720e/github-collapse-in-comment.user.js#L126

For the following block:

line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 10
line 11

I get:

The markdown I used for the code fenching is just backticks: screenshot

For the above block, the numberOfLines is 12 instead of 11, and that's because it takes in the produced innerHTML the closing </code> as a separate line:

screenshot
document.querySelector('.markdown-body pre, .email-signature-reply').innerHTML.split("\n")

2021-06-17_221313

@Mottie, maybe we should add something like .replace('</code>', '') right after .split("\n") ?

PS. Using latest Tampermonkey/Violentmonkey in fresh profile of Chrome 91.

darkred avatar Jun 17 '21 19:06 darkred