@@ -63,9 +63,7 @@ export const mediaMimes = new Set([
6363] ) ;
6464
6565const 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
6967 { regex : / ^ ` ` ` [ \s \S ] * ?` ` ` $ / gm, isMarkdownLink : false , isInline : false } , // In a backtick fenced code block
7068 { regex : / ^ ~ ~ ~ [ \s \S ] * ?~ ~ ~ $ / gm, isMarkdownLink : false , isInline : false } , // In a tildefenced code block
7169 { regex : / ^ \$ \$ [ \s \S ] * ?\$ \$ $ / gm, isMarkdownLink : false , isInline : false } , // In a fenced math block
@@ -79,15 +77,6 @@ export interface SkinnyTextDocument {
7977 readonly uri : vscode . Uri ;
8078}
8179
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-
9180export enum PasteUrlAsFormattedLink {
9281 Always = 'always' ,
9382 Smart = 'smart' ,
@@ -146,6 +135,9 @@ export function checkSmartPaste(document: SkinnyTextDocument, selectedRange: vsc
146135 if ( selectedRange . isEmpty || / ^ [ \s \n ] * $ / . test ( document . getText ( range ) ) || validateLink ( document . getText ( range ) ) . isValid ) {
147136 return false ;
148137 }
138+ if ( / \[ .* \] \( .* \) / . test ( document . getText ( range ) ) || / ! \[ .* \] \( .* \) / . test ( document . getText ( range ) ) ) {
139+ return false ;
140+ }
149141 for ( const regex of smartPasteRegexes ) {
150142 const matches = [ ...document . getText ( ) . matchAll ( regex . regex ) ] ;
151143 for ( const match of matches ) {
0 commit comments