fix(editor): Open links from embedded chat in new tab (#9121)

Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
oleg
2024-04-11 10:57:45 +02:00
committed by GitHub
parent 1cd7eacb7b
commit 284de5d6c7
3 changed files with 38 additions and 12 deletions

View File

@@ -4,6 +4,8 @@ import type { PropType } from 'vue';
import { computed, toRefs } from 'vue';
import VueMarkdown from 'vue-markdown-render';
import hljs from 'highlight.js/lib/core';
import markdownLink from 'markdown-it-link-attributes';
import type MarkdownIt from 'markdown-it';
import type { ChatMessage } from '@n8n/chat/types';
const props = defineProps({
@@ -26,6 +28,15 @@ const classes = computed(() => {
};
});
const linksNewTabPlugin = (vueMarkdownItInstance: MarkdownIt) => {
vueMarkdownItInstance.use(markdownLink, {
attrs: {
target: '_blank',
rel: 'noopener',
},
});
};
const markdownOptions = {
highlight(str: string, lang: string) {
if (lang && hljs.getLanguage(lang)) {
@@ -41,7 +52,12 @@ const markdownOptions = {
<template>
<div class="chat-message" :class="classes">
<slot>
<VueMarkdown class="chat-message-markdown" :source="messageText" :options="markdownOptions" />
<VueMarkdown
class="chat-message-markdown"
:source="messageText"
:options="markdownOptions"
:plugins="[linksNewTabPlugin]"
/>
</slot>
</div>
</template>