Сделал подсветку синтаксиса и кнопки перемещения
This commit is contained in:
@@ -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, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
highlighted.value = Prism.highlight(escaped, Prism.languages['python'], 'python')
|
||||
}
|
||||
|
||||
onMounted(highlight)
|
||||
</script>
|
||||
Reference in New Issue
Block a user