mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-19 18:42:34 +00:00
Support code language name display
This commit is contained in:
parent
d9c1707e1c
commit
13cc3171de
@ -379,6 +379,8 @@ codeblock:
|
|||||||
fold:
|
fold:
|
||||||
enable: false
|
enable: false
|
||||||
height: 500
|
height: 500
|
||||||
|
# Display language name
|
||||||
|
language: false
|
||||||
|
|
||||||
back2top:
|
back2top:
|
||||||
enable: true
|
enable: true
|
||||||
|
|||||||
@ -19,8 +19,7 @@ hexo.extend.helper.register('next_config', function() {
|
|||||||
exturl : theme.exturl,
|
exturl : theme.exturl,
|
||||||
sidebar : theme.sidebar,
|
sidebar : theme.sidebar,
|
||||||
hljswrap : theme.highlight.enable && config.highlight.wrap,
|
hljswrap : theme.highlight.enable && config.highlight.wrap,
|
||||||
copycode : theme.codeblock.copy_button,
|
codeblock : theme.codeblock,
|
||||||
fold : theme.codeblock.fold,
|
|
||||||
bookmark : theme.bookmark,
|
bookmark : theme.bookmark,
|
||||||
mediumzoom: theme.mediumzoom,
|
mediumzoom: theme.mediumzoom,
|
||||||
lazyload : theme.lazyload,
|
lazyload : theme.lazyload,
|
||||||
|
|||||||
@ -30,7 +30,7 @@ if (hexo-config('creative_commons.post')) {
|
|||||||
content: '\f25e';
|
content: '\f25e';
|
||||||
font-family: 'Font Awesome 6 Brands';
|
font-family: 'Font Awesome 6 Brands';
|
||||||
font-size: 200px;
|
font-size: 200px;
|
||||||
opacity: .1;
|
opacity: $watermark-opacity;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: -50px;
|
right: -50px;
|
||||||
top: -150px;
|
top: -150px;
|
||||||
|
|||||||
@ -6,6 +6,15 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.code-lang {
|
||||||
|
font-size: 40px;
|
||||||
|
line-height: 1;
|
||||||
|
opacity: $watermark-opacity;
|
||||||
|
pointer-events: none;
|
||||||
|
position: absolute;
|
||||||
|
right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
.copy-btn {
|
.copy-btn {
|
||||||
color: $black-dim;
|
color: $black-dim;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|||||||
@ -415,3 +415,6 @@ $badge-border-radius = 0;
|
|||||||
$badge-background = $gainsboro;
|
$badge-background = $gainsboro;
|
||||||
$badge-color = $black-light;
|
$badge-color = $black-light;
|
||||||
$badge-text-shadow = none;
|
$badge-text-shadow = none;
|
||||||
|
|
||||||
|
|
||||||
|
$watermark-opacity = .1;
|
||||||
|
|||||||
2
source/js/third-party/tags/mermaid.js
vendored
2
source/js/third-party/tags/mermaid.js
vendored
@ -13,7 +13,7 @@ document.addEventListener('page:loaded', () => {
|
|||||||
newElement.innerHTML = element.innerHTML;
|
newElement.innerHTML = element.innerHTML;
|
||||||
newElement.className = 'mermaid';
|
newElement.className = 'mermaid';
|
||||||
box.appendChild(newElement);
|
box.appendChild(newElement);
|
||||||
if (CONFIG.copycode.enable) {
|
if (CONFIG.codeblock.copy_button.enable) {
|
||||||
NexT.utils.registerCopyButton(box, box, element.textContent);
|
NexT.utils.registerCopyButton(box, box, element.textContent);
|
||||||
}
|
}
|
||||||
const parent = element.parentNode;
|
const parent = element.parentNode;
|
||||||
|
|||||||
@ -89,6 +89,7 @@ NexT.utils = {
|
|||||||
figure.forEach(element => {
|
figure.forEach(element => {
|
||||||
// Skip pre > .mermaid for folding and copy button
|
// Skip pre > .mermaid for folding and copy button
|
||||||
if (element.querySelector('.mermaid')) return;
|
if (element.querySelector('.mermaid')) return;
|
||||||
|
const languageName = [...element.classList].find(cls => cls !== 'highlight');
|
||||||
if (!inited) {
|
if (!inited) {
|
||||||
let span = element.querySelectorAll('.code .line span');
|
let span = element.querySelectorAll('.code .line span');
|
||||||
if (span.length === 0) {
|
if (span.length === 0) {
|
||||||
@ -102,10 +103,10 @@ NexT.utils = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const height = parseInt(window.getComputedStyle(element).height, 10);
|
const height = parseInt(window.getComputedStyle(element).height, 10);
|
||||||
const needFold = CONFIG.fold.enable && (height > CONFIG.fold.height);
|
const needFold = CONFIG.codeblock.fold.enable && (height > CONFIG.codeblock.fold.height);
|
||||||
if (!needFold && !CONFIG.copycode.enable) return;
|
if (!needFold && !CONFIG.codeblock.copy_button.enable && !CONFIG.codeblock.language) return;
|
||||||
let target;
|
let target;
|
||||||
if (CONFIG.hljswrap && CONFIG.copycode.style === 'mac') {
|
if (CONFIG.hljswrap && CONFIG.codeblock.copy_button.style === 'mac') {
|
||||||
target = element;
|
target = element;
|
||||||
} else {
|
} else {
|
||||||
let box = element.querySelector('.code-container');
|
let box = element.querySelector('.code-container');
|
||||||
@ -130,9 +131,15 @@ NexT.utils = {
|
|||||||
target.classList.add('unfold');
|
target.classList.add('unfold');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!inited && CONFIG.copycode.enable) {
|
if (!inited && CONFIG.codeblock.copy_button.enable) {
|
||||||
this.registerCopyButton(target, element);
|
this.registerCopyButton(target, element);
|
||||||
}
|
}
|
||||||
|
if (!inited && CONFIG.codeblock.language && languageName) {
|
||||||
|
const lang = document.createElement('div');
|
||||||
|
lang.className = 'code-lang';
|
||||||
|
lang.innerText = languageName.toUpperCase();
|
||||||
|
target.insertAdjacentElement('afterbegin', lang);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user