Skip to content

Commit

Permalink
fix(editor): Open links from embedded chat in new tab (#9121)
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
  • Loading branch information
OlegIvaniv authored and netroy committed Apr 11, 2024
1 parent b2422ae commit 9e1e799
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
6 changes: 4 additions & 2 deletions packages/@n8n/chat/package.json
Expand Up @@ -40,13 +40,15 @@
},
"dependencies": {
"highlight.js": "^11.8.0",
"markdown-it-link-attributes": "^4.0.1",
"uuid": "^8.3.2",
"vue": "^3.3.4",
"vue-markdown-render": "^2.0.1"
"vue-markdown-render": "^2.1.1"
},
"devDependencies": {
"@n8n/storybook": "workspace:*",
"@iconify-json/mdi": "^1.1.54",
"@n8n/storybook": "workspace:*",
"@types/markdown-it": "^12.2.3",
"shelljs": "^0.8.5",
"unbuild": "^2.0.0",
"unplugin-icons": "^0.17.0",
Expand Down
18 changes: 17 additions & 1 deletion packages/@n8n/chat/src/components/Message.vue
Expand Up @@ -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({
Expand All @@ -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)) {
Expand All @@ -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>
Expand Down
26 changes: 17 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9e1e799

Please sign in to comment.