Skip to content

Commit 6da4e70

Browse files
authored
fix(Link): set high priority to link mark (#568)
1 parent e527cbf commit 6da4e70

File tree

1 file changed

+60
-56
lines changed
  • src/extensions/markdown/Link/LinkSpecs

1 file changed

+60
-56
lines changed

src/extensions/markdown/Link/LinkSpecs/index.ts

Lines changed: 60 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,68 +15,72 @@ export enum LinkAttr {
1515
}
1616

1717
export const LinkSpecs: ExtensionAuto = (builder) => {
18-
builder.addMark(linkMarkName, () => ({
19-
spec: {
20-
attrs: {
21-
[LinkAttr.Href]: {},
22-
[LinkAttr.Title]: {default: null},
23-
[LinkAttr.IsPlaceholder]: {default: false},
24-
[LinkAttr.RawLink]: {default: false},
25-
},
26-
inclusive: false,
27-
parseDOM: [
28-
{
29-
tag: 'a[href]',
30-
getAttrs(dom) {
31-
return {
32-
href: (dom as Element).getAttribute(LinkAttr.Href),
33-
title: (dom as Element).getAttribute(LinkAttr.Title),
34-
};
18+
builder.addMark(
19+
linkMarkName,
20+
() => ({
21+
spec: {
22+
attrs: {
23+
[LinkAttr.Href]: {},
24+
[LinkAttr.Title]: {default: null},
25+
[LinkAttr.IsPlaceholder]: {default: false},
26+
[LinkAttr.RawLink]: {default: false},
27+
},
28+
inclusive: false,
29+
parseDOM: [
30+
{
31+
tag: 'a[href]',
32+
getAttrs(dom) {
33+
return {
34+
href: (dom as Element).getAttribute(LinkAttr.Href),
35+
title: (dom as Element).getAttribute(LinkAttr.Title),
36+
};
37+
},
3538
},
39+
],
40+
toDOM(node) {
41+
return ['a', node.attrs];
3642
},
37-
],
38-
toDOM(node) {
39-
return ['a', node.attrs];
4043
},
41-
},
42-
toMd: {
43-
open(state, mark, parent, index) {
44-
state.isAutolink = isPlainURL(mark, parent, index, 1);
45-
if (state.isAutolink) {
46-
if (mark.attrs[LinkAttr.RawLink]) return '';
47-
return '<';
48-
}
49-
return '[';
50-
},
51-
close(state, mark) {
52-
if (state.isAutolink) {
53-
state.isAutolink = undefined;
54-
if (mark.attrs[LinkAttr.RawLink]) return '';
44+
toMd: {
45+
open(state, mark, parent, index) {
46+
state.isAutolink = isPlainURL(mark, parent, index, 1);
47+
if (state.isAutolink) {
48+
if (mark.attrs[LinkAttr.RawLink]) return '';
49+
return '<';
50+
}
51+
return '[';
52+
},
53+
close(state, mark) {
54+
if (state.isAutolink) {
55+
state.isAutolink = undefined;
56+
if (mark.attrs[LinkAttr.RawLink]) return '';
5557

56-
return '>';
57-
}
58-
state.isAutolink = undefined;
59-
return (
60-
'](' +
61-
escapeParenthesesInUrl(mark.attrs[LinkAttr.Href]) +
62-
(mark.attrs[LinkAttr.Title]
63-
? ' ' + state.quote(mark.attrs[LinkAttr.Title])
64-
: '') +
65-
')'
66-
);
58+
return '>';
59+
}
60+
state.isAutolink = undefined;
61+
return (
62+
'](' +
63+
escapeParenthesesInUrl(mark.attrs[LinkAttr.Href]) +
64+
(mark.attrs[LinkAttr.Title]
65+
? ' ' + state.quote(mark.attrs[LinkAttr.Title])
66+
: '') +
67+
')'
68+
);
69+
},
6770
},
68-
},
69-
fromMd: {
70-
tokenSpec: {
71-
name: linkMarkName,
72-
type: 'mark',
73-
getAttrs: (tok) => ({
74-
href: tok.attrGet('href'),
75-
title: tok.attrGet('title') || null,
76-
}),
71+
fromMd: {
72+
tokenSpec: {
73+
name: linkMarkName,
74+
type: 'mark',
75+
getAttrs: (tok) => ({
76+
href: tok.attrGet('href'),
77+
title: tok.attrGet('title') || null,
78+
}),
79+
},
7780
},
78-
},
79-
}));
81+
}),
82+
builder.Priority.High,
83+
);
8084
};
8185

8286
function isPlainURL(link: Mark, parent: Fragment, index: number, side: number) {

0 commit comments

Comments
 (0)