@@ -63,9 +63,7 @@ export const mediaMimes = new Set([
63
63
] ) ;
64
64
65
65
const smartPasteRegexes = [
66
- { regex : / \[ .* \] \( .* \) / g, isMarkdownLink : true , isInline : true } , // Is a Markdown Link
67
- { regex : / ! \[ .* \] \( .* \) / g, isMarkdownLink : true , isInline : true } , // Is a Markdown Image Link
68
- { regex : / \[ ( [ ^ \] ] * ) \] \( ( [ ^ ) ] * ) \) / g, isMarkdownLink : false , isInline : true } , // In a Markdown link
66
+ { regex : / ( \[ [ ^ \[ \] ] * ] (?: \( [ ^ \( \) ] * \) | \[ [ ^ \[ \] ] * ] ) ) / g, isMarkdownLink : false , isInline : true } , // In a Markdown link
69
67
{ regex : / ^ ` ` ` [ \s \S ] * ?` ` ` $ / gm, isMarkdownLink : false , isInline : false } , // In a backtick fenced code block
70
68
{ regex : / ^ ~ ~ ~ [ \s \S ] * ?~ ~ ~ $ / gm, isMarkdownLink : false , isInline : false } , // In a tildefenced code block
71
69
{ regex : / ^ \$ \$ [ \s \S ] * ?\$ \$ $ / gm, isMarkdownLink : false , isInline : false } , // In a fenced math block
@@ -79,15 +77,6 @@ export interface SkinnyTextDocument {
79
77
readonly uri : vscode . Uri ;
80
78
}
81
79
82
- export interface SmartPaste {
83
-
84
- /**
85
- * `true` if the link is not being pasted within a markdown link, code, or math.
86
- */
87
- pasteAsMarkdownLink : boolean ;
88
-
89
- }
90
-
91
80
export enum PasteUrlAsFormattedLink {
92
81
Always = 'always' ,
93
82
Smart = 'smart' ,
@@ -146,6 +135,9 @@ export function checkSmartPaste(document: SkinnyTextDocument, selectedRange: vsc
146
135
if ( selectedRange . isEmpty || / ^ [ \s \n ] * $ / . test ( document . getText ( range ) ) || validateLink ( document . getText ( range ) ) . isValid ) {
147
136
return false ;
148
137
}
138
+ if ( / \[ .* \] \( .* \) / . test ( document . getText ( range ) ) || / ! \[ .* \] \( .* \) / . test ( document . getText ( range ) ) ) {
139
+ return false ;
140
+ }
149
141
for ( const regex of smartPasteRegexes ) {
150
142
const matches = [ ...document . getText ( ) . matchAll ( regex . regex ) ] ;
151
143
for ( const match of matches ) {
0 commit comments