Сделал подсветку синтаксиса и кнопки перемещения

This commit is contained in:
Ilia Miheev
2026-03-25 00:13:06 +03:00
parent ad78917e91
commit 2c490c8359
8 changed files with 122 additions and 19 deletions
+26
View File
@@ -0,0 +1,26 @@
<template>
<pre><code class="language-python" v-html="highlighted"></code></pre>
</template>
<script setup>
import {ref, onMounted} from 'vue'
import Prism from 'prismjs'
import 'prismjs/components/prism-python'
const props = defineProps({
code: {type: String, required: true},
})
const highlighted = ref('')
function highlight() {
// безопасно экранируем HTML и подсвечиваем через Prism
const escaped = props.code
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
highlighted.value = Prism.highlight(escaped, Prism.languages['python'], 'python')
}
onMounted(highlight)
</script>