mirror of
https://github.com/jaandrle/deka-dom-el
synced 2025-04-02 20:15:53 +02:00
* ⚡ 🎉 * ⚡ wip * 🔤 * ⚡ wip * ⚡ wip * ⚡ Refatc signals to .get/.set syntax #26 * 🐛 Better types for on* * 🔤 * 🔤 * 🐛 coumputed signal * 🔤 ⚡ Docs UI/UX * ⚡ 🔤 UI enhancements * ⚡ (bs) (un)min * 🔤 adds debugging * 🔤 ssr * 🔤 * ⚡ bs/lint * 🔤 * 🔤 UI * 🔤 updates texts * 🔤UI * ⚡ dispatch * 🔤 events * 🔤 elements * 🔤 intro * 🐛 fixes completitions for el with components * 🐛 wrong file(s) in git * 🔤 logo * 🐛 🔤 types 3ps * 🔤 ui/ux * 🔤 * 🔤 * 🔤 scopes * 🔤 * 🔤 ui/ux * 🔤 * ⚡ issignal * 🔤 improvemens * ⚡ irelands * 🔤 UI/UX/wording * 🐛 npx-hint [Scrollable region must have keyboard access | Axe Rules | Deque University | Deque Systems](https://dequeuniversity.com/rules/axe/4.10/scrollable-region-focusable?application=axeAPI) * 🔤 logos * ⚡ better? dts builds * Update README.md
62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
try {
|
|
// Initialize Shiki with our custom theme
|
|
const highlighter = await globalThis.shiki.getHighlighter({
|
|
theme: "css-variables",
|
|
langs: ["javascript", "typescript", "css", "html", "shell"],
|
|
});
|
|
|
|
// Find all code blocks that need highlighting
|
|
const codeBlocks = document.querySelectorAll('div[data-js="todo"] code[class*="language-"]');
|
|
|
|
// Process each code block
|
|
codeBlocks.forEach((block) => {
|
|
try {
|
|
// Get the language from the class
|
|
const langClass = block.className.match(/language-(\w+)/);
|
|
|
|
// Map the language to Shiki format
|
|
let lang = langClass ? langClass[1] : 'javascript';
|
|
if (lang === 'js') lang = 'javascript';
|
|
if (lang === 'ts') lang = 'typescript';
|
|
|
|
// Mark the container as processed
|
|
block.parentElement.dataset.js = "done";
|
|
|
|
// Highlight the code
|
|
const code = block.textContent;
|
|
const html = highlighter.codeToHtml(code, { lang });
|
|
|
|
// Insert the highlighted HTML
|
|
block.innerHTML = html;
|
|
|
|
// Add copy button functionality
|
|
const copyBtn = document.createElement('button');
|
|
copyBtn.className = 'copy-button';
|
|
copyBtn.textContent = 'Copy';
|
|
copyBtn.setAttribute('aria-label', 'Copy code to clipboard');
|
|
copyBtn.addEventListener('click', () => {
|
|
navigator.clipboard.writeText(code).then(() => {
|
|
copyBtn.textContent = 'Copied!';
|
|
setTimeout(() => {
|
|
copyBtn.textContent = 'Copy';
|
|
}, 2000);
|
|
});
|
|
});
|
|
|
|
// Add the copy button to the code block container
|
|
block.parentElement.appendChild(copyBtn);
|
|
} catch (err) {
|
|
console.error('Error highlighting code block:', err);
|
|
// Make sure we don't leave the block in a pending state
|
|
block.parentElement.dataset.js = "error";
|
|
}
|
|
});
|
|
} catch (err) {
|
|
console.error('Failed to initialize Shiki:', err);
|
|
|
|
// Fallback: at least mark blocks as processed so they don't show loading indicator
|
|
document.querySelectorAll('div[data-js="todo"]').forEach(block => {
|
|
block.dataset.js = "error";
|
|
});
|
|
}
|