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