Skip to content

Commit 36cab76

Browse files
committed
fix: extract NcRichTextExternalLink component
- add noExtDecoration prop for reusing the component Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
1 parent ed7419b commit 36cab76

4 files changed

Lines changed: 43 additions & 32 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!--
2+
- SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
- SPDX-License-Identifier: AGPL-3.0-or-later
4+
-->
5+
6+
<script setup lang="ts">
7+
const { href, decorateExternal = false } = defineProps<{
8+
/** Link attribute to render */
9+
href: string
10+
/** Whether to add the appended arrow decoration */
11+
decorateExternal?: boolean
12+
}>()
13+
</script>
14+
15+
<template>
16+
<a
17+
:href="href"
18+
rel="noopener noreferrer"
19+
target="_blank"
20+
:class="[$style.externalLink, {
21+
[$style.externalLink_decorated]: decorateExternal,
22+
}]">
23+
<slot name="default">{{ href }}</slot>
24+
</a>
25+
</template>
26+
27+
<style module lang="scss">
28+
.externalLink {
29+
text-decoration: underline;
30+
}
31+
32+
.externalLink_decorated::after {
33+
content: '';
34+
}
35+
</style>
36+
37+
<docs>
38+
An internal component
39+
</docs>

src/components/NcRichText/autolink.js

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,10 @@
66
import { getBaseUrl, getRootUrl } from '@nextcloud/router'
77
import { u } from 'unist-builder'
88
import { SKIP, visitParents } from 'unist-util-visit-parents'
9+
import NcRichTextExternalLink from './NcRichTextExternalLink.vue'
910
import { logger } from '../../utils/logger.ts'
1011
import { URL_PATTERN_AUTOLINK } from './helpers.js'
1112

12-
const NcLink = {
13-
name: 'NcLink',
14-
props: {
15-
href: {
16-
type: String,
17-
required: true,
18-
},
19-
},
20-
render(h) {
21-
return h('a', {
22-
attrs: {
23-
href: this.href,
24-
rel: 'noopener noreferrer',
25-
target: '_blank',
26-
class: 'rich-text--external-link',
27-
},
28-
}, [this.href.trim()])
29-
},
30-
}
31-
3213
/**
3314
* Remark plugin for autolink parsing
3415
*
@@ -95,7 +76,7 @@ export function parseUrl(text) {
9576
textAfter = lastChar
9677
}
9778
list.push(textBefore)
98-
list.push({ component: NcLink, props: { href } })
79+
list.push({ component: NcRichTextExternalLink, props: { href: href.trim(), decorateExternal: true } })
9980
if (textAfter) {
10081
list.push(textAfter)
10182
}

src/components/NcRichText/placeholder.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function remarkPlaceholder() {
1717
/**
1818
*
1919
* @param {object} node The node
20-
* @param {array} ancestors The parent nodes
20+
* @param {Array} ancestors The parent nodes
2121
*/
2222
function visitor(node, ancestors) {
2323
const parent = ancestors.at(-1)
@@ -59,11 +59,9 @@ export function prepareTextNode({ h, context }, text) {
5959
return entry
6060
}
6161
const { component, props } = entry
62-
// do not override class of NcLink
63-
const componentClass = component.name === 'NcLink' ? undefined : 'rich-text--component'
6462
return h(component, {
6563
props,
66-
class: componentClass,
64+
class: 'rich-text--component',
6765
})
6866
})
6967
}

src/components/NcRichText/richtext.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
.rich-text--fallback, .rich-text-component {
1515
display: inline;
1616
}
17-
18-
.rich-text--external-link {
19-
text-decoration: underline;
20-
&:after {
21-
content: '';
22-
}
23-
}
2417
}
2518

2619
/* Markdown styles */

0 commit comments

Comments
 (0)