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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 12 deletions

View file

@ -40,13 +40,15 @@
}, },
"dependencies": { "dependencies": {
"highlight.js": "^11.8.0", "highlight.js": "^11.8.0",
"markdown-it-link-attributes": "^4.0.1",
"uuid": "^8.3.2", "uuid": "^8.3.2",
"vue": "^3.3.4", "vue": "^3.3.4",
"vue-markdown-render": "^2.0.1" "vue-markdown-render": "^2.1.1"
}, },
"devDependencies": { "devDependencies": {
"@n8n/storybook": "workspace:*",
"@iconify-json/mdi": "^1.1.54", "@iconify-json/mdi": "^1.1.54",
"@n8n/storybook": "workspace:*",
"@types/markdown-it": "^12.2.3",
"shelljs": "^0.8.5", "shelljs": "^0.8.5",
"unbuild": "^2.0.0", "unbuild": "^2.0.0",
"unplugin-icons": "^0.17.0", "unplugin-icons": "^0.17.0",

View file

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

View file

@ -143,6 +143,9 @@ importers:
highlight.js: highlight.js:
specifier: ^11.8.0 specifier: ^11.8.0
version: 11.9.0 version: 11.9.0
markdown-it-link-attributes:
specifier: ^4.0.1
version: 4.0.1
uuid: uuid:
specifier: ^8.3.2 specifier: ^8.3.2
version: 8.3.2 version: 8.3.2
@ -150,8 +153,8 @@ importers:
specifier: ^3.3.4 specifier: ^3.3.4
version: 3.3.4 version: 3.3.4
vue-markdown-render: vue-markdown-render:
specifier: ^2.0.1 specifier: ^2.1.1
version: 2.0.1 version: 2.1.1(vue@3.3.4)
devDependencies: devDependencies:
'@iconify-json/mdi': '@iconify-json/mdi':
specifier: ^1.1.54 specifier: ^1.1.54
@ -159,6 +162,9 @@ importers:
'@n8n/storybook': '@n8n/storybook':
specifier: workspace:* specifier: workspace:*
version: link:../storybook version: link:../storybook
'@types/markdown-it':
specifier: ^12.2.3
version: 12.2.3
shelljs: shelljs:
specifier: ^0.8.5 specifier: ^0.8.5
version: 0.8.5 version: 0.8.5
@ -26000,13 +26006,6 @@ packages:
vue: 3.4.21(typescript@5.4.2) vue: 3.4.21(typescript@5.4.2)
dev: false dev: false
/vue-markdown-render@2.0.1:
resolution: {integrity: sha512-/UBCu0OrZ9zzEDtiZVwlV/CQ+CgcwViServGis3TRXSVc6+6lJxcaOcD43vRoQzYfPa9r9WDt0Q7GyupOmpEWA==}
dependencies:
markdown-it: 12.3.2
vue: 3.3.4
dev: false
/vue-markdown-render@2.0.1(typescript@5.4.2): /vue-markdown-render@2.0.1(typescript@5.4.2):
resolution: {integrity: sha512-/UBCu0OrZ9zzEDtiZVwlV/CQ+CgcwViServGis3TRXSVc6+6lJxcaOcD43vRoQzYfPa9r9WDt0Q7GyupOmpEWA==} resolution: {integrity: sha512-/UBCu0OrZ9zzEDtiZVwlV/CQ+CgcwViServGis3TRXSVc6+6lJxcaOcD43vRoQzYfPa9r9WDt0Q7GyupOmpEWA==}
dependencies: dependencies:
@ -26016,6 +26015,15 @@ packages:
- typescript - typescript
dev: false dev: false
/vue-markdown-render@2.1.1(vue@3.3.4):
resolution: {integrity: sha512-szuJVbCwgIpVsggd8IHGB2lLo8BH8Ojd+wakaOTASNxdYcccKxoMcvDqUsLoGwgKDY8yJf0U/+ppffEYxsEHkA==}
peerDependencies:
vue: ^3.3.4
dependencies:
markdown-it: 12.3.2
vue: 3.3.4
dev: false
/vue-router@4.2.2(vue@3.4.21): /vue-router@4.2.2(vue@3.4.21):
resolution: {integrity: sha512-cChBPPmAflgBGmy3tBsjeoe3f3VOSG6naKyY5pjtrqLGbNEXdzCigFUHgBvp9e3ysAtFtEx7OLqcSDh/1Cq2TQ==} resolution: {integrity: sha512-cChBPPmAflgBGmy3tBsjeoe3f3VOSG6naKyY5pjtrqLGbNEXdzCigFUHgBvp9e3ysAtFtEx7OLqcSDh/1Cq2TQ==}
peerDependencies: peerDependencies: