✨ feat: enable adding URL/path to code blocks (#307)
parent
0cbd727f25
commit
b70efd1642
@ -0,0 +1,20 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
@ -0,0 +1 @@
|
||||
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))})});
|
@ -0,0 +1 @@
|
||||
<span class="code-source hidden" data-source="{{ src | safe }}"></span>
|
Loading…
Reference in New Issue