mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 09:08:53 +01:00
Fixed markdown regular expression (#189423)
* fixed md regex * update shared.ts
This commit is contained in:
@@ -63,9 +63,7 @@ export const mediaMimes = new Set([
|
||||
]);
|
||||
|
||||
const smartPasteRegexes = [
|
||||
{ regex: /\[.*\]\(.*\)/g, isMarkdownLink: true, isInline: true }, // Is a Markdown Link
|
||||
{ regex: /!\[.*\]\(.*\)/g, isMarkdownLink: true, isInline: true }, // Is a Markdown Image Link
|
||||
{ regex: /\[([^\]]*)\]\(([^)]*)\)/g, isMarkdownLink: false, isInline: true }, // In a Markdown link
|
||||
{ regex: /(\[[^\[\]]*](?:\([^\(\)]*\)|\[[^\[\]]*]))/g, isMarkdownLink: false, isInline: true }, // In a Markdown link
|
||||
{ regex: /^```[\s\S]*?```$/gm, isMarkdownLink: false, isInline: false }, // In a backtick fenced code block
|
||||
{ regex: /^~~~[\s\S]*?~~~$/gm, isMarkdownLink: false, isInline: false }, // In a tildefenced code block
|
||||
{ regex: /^\$\$[\s\S]*?\$\$$/gm, isMarkdownLink: false, isInline: false }, // In a fenced math block
|
||||
@@ -79,15 +77,6 @@ export interface SkinnyTextDocument {
|
||||
readonly uri: vscode.Uri;
|
||||
}
|
||||
|
||||
export interface SmartPaste {
|
||||
|
||||
/**
|
||||
* `true` if the link is not being pasted within a markdown link, code, or math.
|
||||
*/
|
||||
pasteAsMarkdownLink: boolean;
|
||||
|
||||
}
|
||||
|
||||
export enum PasteUrlAsFormattedLink {
|
||||
Always = 'always',
|
||||
Smart = 'smart',
|
||||
@@ -146,6 +135,9 @@ export function checkSmartPaste(document: SkinnyTextDocument, selectedRange: vsc
|
||||
if (selectedRange.isEmpty || /^[\s\n]*$/.test(document.getText(range)) || validateLink(document.getText(range)).isValid) {
|
||||
return false;
|
||||
}
|
||||
if (/\[.*\]\(.*\)/.test(document.getText(range)) || /!\[.*\]\(.*\)/.test(document.getText(range))) {
|
||||
return false;
|
||||
}
|
||||
for (const regex of smartPasteRegexes) {
|
||||
const matches = [...document.getText().matchAll(regex.regex)];
|
||||
for (const match of matches) {
|
||||
|
||||
Reference in New Issue
Block a user