Skip to content

Commit

Permalink
Fix Hljs without line_number and wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Jul 26, 2023
1 parent ff0a130 commit 5663b5d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/label-commenter-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ labels:
issue:
body: This will not be worked on but we appreciate your contribution.
action: close
- name: Configurations
- name: Configuration
labeled:
pr:
body: |
Expand Down
19 changes: 12 additions & 7 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,27 @@ NexT.utils = {

registerCodeblock: function() {
let figure = document.querySelectorAll('figure.highlight');
let isHljs = true;
let isHljsWithWrap = true;
if (figure.length === 0) {
figure = document.querySelectorAll('pre:not(.mermaid)');
isHljs = false;
isHljsWithWrap = false;
}
figure.forEach(element => {
element.querySelectorAll('.code .line span').forEach(span => {
span.classList.forEach(name => {
span.classList.replace(name, `hljs-${name}`);
let span = element.querySelectorAll('.code .line span');
if (span.length === 0) {
// Hljs without line_number and wrap
span = element.querySelectorAll('code.highlight span');
}
span.forEach(s => {
s.classList.forEach(name => {
s.classList.replace(name, `hljs-${name}`);
});
});
const height = parseInt(window.getComputedStyle(element).height.replace('px', ''), 10);
const needFold = CONFIG.fold.enable && (height > CONFIG.fold.height);
if (!needFold && !CONFIG.copycode.enable) return;
let target;
if (isHljs && CONFIG.copycode.style === 'mac') {
if (isHljsWithWrap && CONFIG.copycode.style === 'mac') {
target = element;
} else {
// https://github.com/next-theme/hexo-theme-next/issues/98
Expand All @@ -69,7 +74,7 @@ NexT.utils = {
}
if (needFold) {
target.classList.add('highlight-fold');
target.insertAdjacentHTML('beforeend', '<div class="fold-cover"></div><div class="expand-btn"><i class="fa fa-chevron-down fa-fw"></i></div>');
target.insertAdjacentHTML('beforeend', '<div class="fold-cover"></div><div class="expand-btn"><i class="fa fa-angle-down fa-fw"></i></div>');
target.querySelector('.expand-btn').addEventListener('click', () => {
target.classList.remove('highlight-fold');
});
Expand Down

0 comments on commit 5663b5d

Please sign in to comment.