diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/NewsItem.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/NewsItem.vue index 0d0f8604d..bbad4315c 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/NewsItem.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/NewsItem.vue @@ -120,10 +120,28 @@ const truncateContent = (content: string): string => { return truncatedContent; }; +const preprocess = (markdown: string): string => { + return markdown; +} + +const postprocess = (html: string): string => { + DOMPurify.addHook('afterSanitizeAttributes', (node) => { + 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); - // console.log(rawHtml) - return DOMPurify.sanitize(rawHtml) + return rawHtml; }; const prepareContent = (content: string): string => {