mirror of
https://ghfast.top/https://github.com/zsjy/halo-theme-dream2.0-plus.git
synced 2025-03-15 08:29:40 +08:00
fix line number
This commit is contained in:
parent
e4ac498755
commit
8f5fb2a8a1
@ -42,13 +42,16 @@ const postContext = {
|
||||
}
|
||||
// 生成行号
|
||||
let codes = $(this).text().split('\n') || []
|
||||
let nums = codes.length
|
||||
let nums = codes.length-1
|
||||
let lineDigit = String(nums).length
|
||||
if (lineDigit === 1) lineDigit = 2
|
||||
let lis = ''
|
||||
for (var i = 0; i < nums; i++) {
|
||||
lis += `<li ${(lines && /^\s*\|\+\s+/.test(codes[i]))? 'class="code-select"' : ''}>${String(i + 1).padStart(lineDigit, 0)}</li>`
|
||||
}
|
||||
if (codes[nums].trim() !== '') {
|
||||
lis += `<li ${(lines && /^\s*\|\+\s+/.test(codes[i]))? 'class="code-select"' : ''}>${String(nums + 1).padStart(lineDigit, 0)}</li>`
|
||||
}
|
||||
if (lines) {
|
||||
$(this).text($(this).text().replace(/(^\s*)\|\+\s/gm,'$1'))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user