@@ -15,68 +15,72 @@ export enum LinkAttr {
15
15
}
16
16
17
17
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
+ } ,
35
38
} ,
39
+ ] ,
40
+ toDOM ( node ) {
41
+ return [ 'a' , node . attrs ] ;
36
42
} ,
37
- ] ,
38
- toDOM ( node ) {
39
- return [ 'a' , node . attrs ] ;
40
43
} ,
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 '' ;
55
57
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
+ } ,
67
70
} ,
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
+ } ,
77
80
} ,
78
- } ,
79
- } ) ) ;
81
+ } ) ,
82
+ builder . Priority . High ,
83
+ ) ;
80
84
} ;
81
85
82
86
function isPlainURL ( link : Mark , parent : Fragment , index : number , side : number ) {
0 commit comments