Skip to content

Commit 53318b4

Browse files
committed
get real link url
1 parent 87f1f3c commit 53318b4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/editor/lib/plugins/cleanup.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ function createDecorations(view, decorations = Decoration.none) {
109109
enter(node) {
110110
if (node.name.startsWith('headline'))
111111
headlineRange = { from: node.from, to: node.to }
112-
if (node.name === 'link') linkRange = { from: node.from, to: node.to }
113112

114113
if (node.name === 'link') {
114+
linkRange = { from: node.from, to: node.to }
115115
decorations = decorations.update({
116116
add: [
117117
// TODO: get the real url
@@ -129,6 +129,20 @@ function createDecorations(view, decorations = Decoration.none) {
129129
})
130130
}
131131

132+
if (node.name === 'url') {
133+
if (linkRange === null) return
134+
// get text of node
135+
const text = view.state.doc.sliceString(node.from, node.to)
136+
decorations = decorations.update({
137+
add: [
138+
Decoration.mark({
139+
tagName: 'a',
140+
attributes: { class: 'cm-link', href: text.slice(1, -1) },
141+
}).range(linkRange.from, linkRange.to),
142+
],
143+
})
144+
}
145+
132146
if (node.name === 'url' || node.name === 'mark') {
133147
decorations = decorations.update({
134148
add: [hide(linkRange).range(node.from, node.to)],

0 commit comments

Comments
 (0)