forked from deepStateMirrors/tabi
✨ feat: support Zola's native code block names (#489)
This commit is contained in:
parent
6837f6f4f1
commit
61793b2e56
23 changed files with 228 additions and 195 deletions
|
@ -1,20 +0,0 @@
|
|||
document.addEventListener("DOMContentLoaded", function() {
|
||||
document.querySelectorAll('.code-source').forEach(function(marker) {
|
||||
let sourceUrl = marker.getAttribute('data-source');
|
||||
let nextPre = marker.nextElementSibling;
|
||||
|
||||
if (nextPre && nextPre.tagName === 'PRE') {
|
||||
let codeElement = nextPre.querySelector('code');
|
||||
if (codeElement) {
|
||||
// Use a span element for the source path if it's not a link.
|
||||
let sourceElement = document.createElement(sourceUrl.startsWith('http') ? 'a' : 'span');
|
||||
sourceElement.textContent = sourceUrl;
|
||||
sourceElement.className = 'source-path';
|
||||
if (sourceUrl.startsWith('http')) {
|
||||
sourceElement.href = sourceUrl;
|
||||
}
|
||||
codeElement.prepend(sourceElement);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
1
static/js/addSrcToCodeBlock.min.js
vendored
1
static/js/addSrcToCodeBlock.min.js
vendored
|
@ -1 +0,0 @@
|
|||
document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(".code-source").forEach(function(t){var e,n=t.getAttribute("data-source"),t=t.nextElementSibling;t&&"PRE"===t.tagName&&(t=t.querySelector("code"))&&((e=document.createElement(n.startsWith("http")?"a":"span")).textContent=n,e.className="source-path",n.startsWith("http")&&(e.href=n),t.prepend(e))})});
|
36
static/js/codeBlockNameLinks.js
Normal file
36
static/js/codeBlockNameLinks.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
document.addEventListener("DOMContentLoaded", function() {
|
||||
// Convert URLs in data-name to links.
|
||||
document.querySelectorAll('code[data-name]').forEach(function(code) {
|
||||
const name = code.getAttribute('data-name');
|
||||
if (name.startsWith('http')) {
|
||||
const link = document.createElement('a');
|
||||
link.href = name;
|
||||
link.className = 'source-path';
|
||||
link.textContent = name;
|
||||
code.insertBefore(link, code.firstChild);
|
||||
// Remove data-name to avoid overlap with Zola's native display.
|
||||
code.removeAttribute('data-name');
|
||||
code.parentElement?.removeAttribute('data-name');
|
||||
}
|
||||
});
|
||||
|
||||
// Legacy support for old shortcode. https://github.com/welpo/tabi/pull/489
|
||||
document.querySelectorAll('.code-source').forEach(function(marker) {
|
||||
const sourceUrl = marker.getAttribute('data-source');
|
||||
const nextPre = marker.nextElementSibling;
|
||||
if (nextPre?.tagName === 'PRE') {
|
||||
const code = nextPre.querySelector('code');
|
||||
if (code) {
|
||||
if (sourceUrl.startsWith('http')) {
|
||||
const link = document.createElement('a');
|
||||
link.href = sourceUrl;
|
||||
link.className = 'source-path';
|
||||
link.textContent = sourceUrl;
|
||||
code.insertBefore(link, code.firstChild);
|
||||
} else {
|
||||
code.setAttribute('data-name', sourceUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
1
static/js/codeBlockNameLinks.min.js
vendored
Normal file
1
static/js/codeBlockNameLinks.min.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll("code[data-name]").forEach(function(e){var t,a=e.getAttribute("data-name");a.startsWith("http")&&((t=document.createElement("a")).href=a,t.className="source-path",t.textContent=a,e.insertBefore(t,e.firstChild),e.removeAttribute("data-name"),e.parentElement?.removeAttribute("data-name"))}),document.querySelectorAll(".code-source").forEach(function(e){var t,a=e.getAttribute("data-source");"PRE"===(e=e.nextElementSibling)?.tagName&&(e=e.querySelector("code"))&&(a.startsWith("http")?((t=document.createElement("a")).href=a,t.className="source-path",t.textContent=a,e.insertBefore(t,e.firstChild)):e.setAttribute("data-name",a))})});
|
Loading…
Add table
Add a link
Reference in a new issue