2019-01-27 06:34:52 +01:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<code v-if="inline" :class="`language-${prismLang}`" v-html="html"></code>
|
|
|
|
<pre
|
|
|
|
v-else
|
|
|
|
:class="`language-${prismLang}`"
|
|
|
|
><code :class="`language-${prismLang}`" v-html="html"></code></pre>
|
2019-01-27 06:34:52 +01:00
|
|
|
</template>
|
|
|
|
|
2022-01-10 16:05:18 +01:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import { computed } from "vue";
|
|
|
|
import Prism from "prismjs";
|
|
|
|
import "prismjs/themes/prism-okaidia.css";
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-01-10 16:05:18 +01:00
|
|
|
const props = defineProps<{
|
|
|
|
code: string;
|
|
|
|
lang?: string;
|
|
|
|
inline?: boolean;
|
|
|
|
}>();
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const prismLang = computed(() =>
|
2023-07-13 23:45:54 +02:00
|
|
|
Prism.languages[props.lang] ? props.lang : "plaintext",
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
|
|
|
const html = computed(() =>
|
|
|
|
Prism.highlight(
|
|
|
|
props.code,
|
|
|
|
Prism.languages[prismLang.value],
|
2023-07-06 03:28:27 +02:00
|
|
|
prismLang.value,
|
|
|
|
),
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2019-01-27 06:34:52 +01:00
|
|
|
</script>
|