Last active
March 22, 2025 10:16
-
-
Save atomjoy/d69a7f136caa7d47f40d048a659c31ee to your computer and use it in GitHub Desktop.
Vue 3 Shiki Highlighter component (multipe code tags)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script setup> | |
import { codeToHtml } from 'https://esm.sh/[email protected]'; | |
import { onMounted } from 'vue'; | |
onMounted(() => { | |
const all = document.querySelectorAll('code'); | |
all.forEach(async (f) => { | |
const theme = ['github-light', 'slack-ochin', 'vitesse-light', 'everforest-light', 'everforest-dark', 'vitesse-dark', 'one-dark-pro', 'synthwave-84', 'gruvbox-dark-medium', 'gruvbox-dark-soft', 'gruvbox-light-soft', 'rose-pine', 'rose-pine-moon', 'rose-pine-dawn', 'plastic', 'laserwave', 'kanagawa-dragon', 'kanagawa-wave', 'material-theme', 'material-theme-darker']; | |
let code = f.innerText; | |
f.innerHTML = await codeToHtml(code, { lang: 'php', theme: theme[0] }); | |
}); | |
}); | |
let code = ` | |
<h1>Hello from Vue</h1> | |
<pre><code> | |
<?php | |
echo '1 Htmlentities code string between <code> tags. Change < to < in string, remove js <script> and onevent="" from html.'; | |
?> | |
</code></pre> | |
<p>Ale krótki tekst.</p> | |
<pre><code> | |
<?php | |
echo "2 Htmlentities code string between <code> tags. Change < to < in string."; | |
?> | |
</code></pre> | |
`; | |
</script> | |
<template> | |
<div v-html="code" /> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment