From e6745c4887214196d30c05c28abf2df4201cb5f2 Mon Sep 17 00:00:00 2001 From: RitvikSardana Date: Tue, 29 Oct 2024 18:09:26 +0530 Subject: [PATCH 1/2] fix: allow controls on video html elements in tip tap --- desk/src/components/TextEditor.vue | 4 +- desk/src/pages/KnowledgeBaseArticle.vue | 29 +----------- desk/src/pages/ticket/TicketCommunication.vue | 7 ++- desk/src/pages/ticket/TicketTextEditor.vue | 2 +- desk/src/tiptap-extensions.ts | 44 +++++++++++++++++++ 5 files changed, 56 insertions(+), 30 deletions(-) create mode 100644 desk/src/tiptap-extensions.ts diff --git a/desk/src/components/TextEditor.vue b/desk/src/components/TextEditor.vue index 9b5d1b7fd..f69002250 100644 --- a/desk/src/components/TextEditor.vue +++ b/desk/src/components/TextEditor.vue @@ -2,6 +2,7 @@
(), { diff --git a/desk/src/pages/KnowledgeBaseArticle.vue b/desk/src/pages/KnowledgeBaseArticle.vue index 06e6326a2..4165cc881 100644 --- a/desk/src/pages/KnowledgeBaseArticle.vue +++ b/desk/src/pages/KnowledgeBaseArticle.vue @@ -94,15 +94,14 @@ import { import { createToast } from "@/utils"; import { useAuthStore } from "@/stores/auth"; import { useError } from "@/composables/error"; - -import { LayoutHeader, PageTitle } from "@/components"; +import { LayoutHeader } from "@/components"; import KnowledgeBaseArticleActionsEdit from "./knowledge-base/KnowledgeBaseArticleActionsEdit.vue"; import KnowledgeBaseArticleActionsNew from "./knowledge-base/KnowledgeBaseArticleActionsNew.vue"; import KnowledgeBaseArticleActionsView from "./knowledge-base/KnowledgeBaseArticleActionsView.vue"; import KnowledgeBaseArticleTopEdit from "./knowledge-base/KnowledgeBaseArticleTopEdit.vue"; import KnowledgeBaseArticleTopNew from "./knowledge-base/KnowledgeBaseArticleTopNew.vue"; import KnowledgeBaseArticleTopView from "./knowledge-base/KnowledgeBaseArticleTopView.vue"; -import { Extension } from "@tiptap/core"; +import { PreserveIds } from "@/tiptap-extensions"; const props = defineProps({ articleId: { @@ -390,30 +389,6 @@ const textEditorMenuButtons = [ ], ]; -// extension to preserve ids in html of headings -const PreserveIds: Extension = Extension.create({ - name: "preserveIds", - addGlobalAttributes() { - return [ - { - types: ["heading"], - attributes: { - id: { - default: null, - parseHTML: (element) => element.getAttribute("id"), - renderHTML: (attributes) => { - if (!attributes.id) { - return {}; - } - return { id: attributes.id }; - }, - }, - }, - }, - ]; - }, -}); - const textEditorContentWithIDs = computed(() => article.data?.content ? addLinksToHeadings(article.data?.content) : null ); diff --git a/desk/src/pages/ticket/TicketCommunication.vue b/desk/src/pages/ticket/TicketCommunication.vue index 61b26de94..430308aac 100644 --- a/desk/src/pages/ticket/TicketCommunication.vue +++ b/desk/src/pages/ticket/TicketCommunication.vue @@ -54,7 +54,12 @@ withDefaults(defineProps

(), { function sanitize(html: string) { return sanitizeHtml(html, { - allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]), + allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img", "video"]), + allowedAttributes: { + a: ["href"], + video: ["src", "controls"], + img: ["src"], + }, }); } diff --git a/desk/src/pages/ticket/TicketTextEditor.vue b/desk/src/pages/ticket/TicketTextEditor.vue index 06966e0c4..e1e1b4a97 100644 --- a/desk/src/pages/ticket/TicketTextEditor.vue +++ b/desk/src/pages/ticket/TicketTextEditor.vue @@ -75,6 +75,7 @@