Skip to content

Commit 8d18ec7

Browse files
authored
fix(editor): relative links must no be targetted as _blank (#170)
1 parent d9f6840 commit 8d18ec7

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

src/app/src/components/content/ContentEditorTipTap.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ const toolbarItems = computed(() => getStandardToolbarItems(t))
171171
:handlers="customHandlers"
172172
:starter-kit="{
173173
codeBlock: false,
174+
link: {
175+
HTMLAttributes: {
176+
target: null,
177+
},
178+
},
174179
}"
175180
:extensions="[
176181
Frontmatter,

src/app/test/unit/utils/tiptap.test.ts

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('paragraph', () => {
112112
expect(outputContent).toBe(`${inputContent}\n`)
113113
})
114114

115-
test('link', async () => {
115+
test('external link', async () => {
116116
const inputContent = '[Link](https://example.com)'
117117

118118
const expectedMDCJSON: MDCRoot = {
@@ -192,6 +192,84 @@ describe('paragraph', () => {
192192
expect(outputContent).toBe(`${inputContent}\n`)
193193
})
194194

195+
test('relative link', async () => {
196+
const inputContent = '[Link](/test)'
197+
198+
const expectedMDCJSON: MDCRoot = {
199+
type: 'root',
200+
children: [
201+
{
202+
type: 'element',
203+
tag: 'p',
204+
props: {},
205+
children: [
206+
{
207+
type: 'element',
208+
tag: 'a',
209+
props: {
210+
href: '/test',
211+
},
212+
children: [
213+
{
214+
type: 'text',
215+
value: 'Link',
216+
},
217+
],
218+
},
219+
],
220+
},
221+
],
222+
}
223+
224+
const expectedTiptapJSON: JSONContent = {
225+
type: 'doc',
226+
content: [
227+
{
228+
type: 'frontmatter',
229+
attrs: {
230+
frontmatter: {},
231+
},
232+
},
233+
{
234+
type: 'paragraph',
235+
attrs: {},
236+
content: [
237+
{
238+
type: 'text',
239+
marks: [
240+
{
241+
type: 'link',
242+
attrs: {
243+
href: '/test',
244+
},
245+
},
246+
],
247+
text: 'Link',
248+
},
249+
],
250+
},
251+
],
252+
}
253+
254+
const document = await generateDocumentFromContent('test.md', inputContent, { compress: false }) as DatabasePageItem
255+
expect(document.body).toMatchObject(expectedMDCJSON)
256+
257+
const tiptapJSON: JSONContent = await mdcToTiptap(document.body as unknown as MDCRoot, {})
258+
expect(tiptapJSON).toMatchObject(expectedTiptapJSON)
259+
260+
const generatedMdcJSON = await tiptapToMDC(tiptapJSON)
261+
expect(generatedMdcJSON.body).toMatchObject(expectedMDCJSON)
262+
263+
const generatedDocument = createMockDocument('docs/test.md', {
264+
body: generatedMdcJSON.body as unknown as MarkdownRoot,
265+
...generatedMdcJSON.data,
266+
})
267+
268+
const outputContent = await generateContentFromDocument(generatedDocument)
269+
270+
expect(outputContent).toBe(`${inputContent}\n`)
271+
})
272+
195273
test('inline component', async () => {
196274
const inputContent = 'This is a :badge component'
197275

0 commit comments

Comments
 (0)