Files
mealie/frontend/app/components/global/SafeMarkdown.vue

48 lines
887 B
Vue
Raw Normal View History

<template>
<!-- eslint-disable-next-line vue/no-v-html is safe here because all HTML is sanitized with DOMPurify in setup() -->
<div v-html="value" />
</template>
2026-03-23 21:18:25 +01:00
<script setup lang="ts">
import { marked } from "marked";
import { sanitizeMarkdownHtml } from "~/lib/sanitize/markdown";
2026-02-01 16:24:57 -06:00
2026-03-23 21:18:25 +01:00
const props = defineProps({
source: {
type: String,
default: "",
},
2026-03-23 21:18:25 +01:00
});
2026-02-01 16:24:57 -06:00
const { $appInfo } = useNuxtApp();
2026-03-23 21:18:25 +01:00
const value = computed(() => {
const rawHtml = marked.parse(props.source || "", { async: false, breaks: true });
return sanitizeMarkdownHtml(rawHtml, $appInfo?.allowedIframeHosts ?? []);
});
</script>
<style scoped>
:deep(table) {
border-collapse: collapse;
width: 100%;
}
:deep(th),
:deep(td) {
border: 1px solid;
padding: 8px;
text-align: left;
}
:deep(th) {
font-weight: bold;
}
:deep(ul),
:deep(ol) {
margin: 8px 0;
padding-left: 20px;
}
</style>