mirror of
https://github.com/welpo/tabi.git
synced 2025-12-17 04:48:44 +01:00
✨ feat: enable adding URL/path to code blocks (#307)
This commit is contained in:
parent
0cbd727f25
commit
b70efd1642
17 changed files with 175 additions and 10 deletions
20
static/js/addSrcToCodeBlock.js
Normal file
20
static/js/addSrcToCodeBlock.js
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue