Skip to content

Commit

Permalink
perf: 优化代码块行号偶尔少一个的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
Asteri5m committed Dec 11, 2024
1 parent e037972 commit c66e850
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/js/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ const postContext = {
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'))
}
Expand Down

0 comments on commit c66e850

Please sign in to comment.