fix content parsing

This commit is contained in:
2023-07-11 21:50:49 +10:00
parent e723831548
commit c4e017c7b7

View File

@@ -1,5 +1,5 @@
<template> <template>
<component :is="computedContent.template"></component> <component :is="computedContent"></component>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@@ -23,7 +23,10 @@ const computedContent = computed(() => {
let html = ""; let html = "";
// Sanitize HTML // Sanitize HTML
html = DOMPurify.sanitize(html); html = DOMPurify.sanitize(props.html);
// Convert nl to <br>
html = html.replaceAll("\n", "<br />");
// Convert local links to router-links // Convert local links to router-links
const regexHref = new RegExp( const regexHref = new RegExp(
@@ -32,7 +35,7 @@ const computedContent = computed(() => {
}(.*?>.*?)</a>`, }(.*?>.*?)</a>`,
"ig", "ig",
); );
html = props.html.replace(regexHref, '<router-link $1to="$2</router-link>'); html = html.replace(regexHref, '<router-link $1to="$2</router-link>');
// Convert image galleries to SMImageGallery component // Convert image galleries to SMImageGallery component
// const regexGallery = // const regexGallery =
@@ -64,16 +67,6 @@ const computedContent = computed(() => {
}/uploads/$2?size=large"`, }/uploads/$2?size=large"`,
); );
return { return { template: `<div class="html">${html}</div>` };
template: `<div class="html">${html}</div>`,
...{},
};
// return {
// template: `<div class="html">${html}</div>`,
// // components: {
// // SMImageGallery,
// // },
// };
}); });
</script> </script>