Rendre les commentaire markdown

This commit is contained in:
Boris Waaub 2024-05-13 11:59:50 +02:00
parent 821fce3dd8
commit d6f5eae0c9
2 changed files with 45 additions and 9 deletions

View File

@ -18,8 +18,6 @@
v-model="content" v-model="content"
tag-name="textarea"> tag-name="textarea">
</ckeditor> </ckeditor>
<!-- <textarea v-model="content" class="form-control" id="content" rows="3"
:placeholder="$t('comment.label')"></textarea> -->
<div class="d-flex justify-content-end p-2"> <div class="d-flex justify-content-end p-2">
<button class="btn btn-chill-green text-white float-right" type="submit"> <button class="btn btn-chill-green text-white float-right" type="submit">

View File

@ -2,28 +2,66 @@
<div class="col-12"> <div class="col-12">
<i class="fa fa-comment"></i> <i class="fa fa-comment"></i>
<span class="mx-1"> <span class="mx-1">
{{ $t('history.comment',{ comment: commentHistory.content}) }} {{ $t("history.comment") }}
</span> </span>
<div class="mt-2">
<div v-html="convertMarkdownToHtml(commentHistory.content)"></div>
</div>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { PropType, defineComponent } from "vue";
import { PropType, defineComponent } from 'vue'; import { marked } from "marked";
import DOMPurify from "dompurify";
// Types // Types
import { Comment } from '../../../types'; import { Comment } from "../../../types";
export default defineComponent({ export default defineComponent({
name: 'TicketHistoryCommentComponent', name: "TicketHistoryCommentComponent",
props: { props: {
commentHistory: { commentHistory: {
type: Object as PropType<Comment>, type: Object as PropType<Comment>,
required: true, required: true,
}, },
}, },
setup() {} setup() {
const preprocess = (markdown: string): string => {
return markdown;
};
const postprocess = (html: string): string => {
DOMPurify.addHook("afterSanitizeAttributes", (node: any) => {
if ("target" in node) {
node.setAttribute("target", "_blank");
node.setAttribute("rel", "noopener noreferrer");
}
if (
!node.hasAttribute("target") &&
(node.hasAttribute("xlink:href") ||
node.hasAttribute("href"))
) {
node.setAttribute("xlink:show", "new");
}
});
return DOMPurify.sanitize(html);
};
const convertMarkdownToHtml = (markdown: string): string => {
marked.use({ hooks: { postprocess, preprocess } });
const rawHtml = marked(markdown) as string;
return rawHtml;
};
return {
convertMarkdownToHtml,
};
},
}); });
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped>
</style>