mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-20 16:49:06 +01:00
Automatic markdown pasting should escape parentheses (#189357)
auto link with mismatched parens
This commit is contained in:
@@ -214,9 +214,9 @@ export function appendToLinkSnippet(
|
||||
if (pasteAsMarkdownLink) {
|
||||
snippet.appendText('[');
|
||||
snippet.appendPlaceholder(escapeBrackets(title) || 'Title', placeholderValue);
|
||||
snippet.appendText(isExternalLink ? `](${uriString})` : `](${escapeMarkdownLinkPath(mdPath)})`);
|
||||
snippet.appendText(`](${escapeMarkdownLinkPath(isExternalLink ? uriString : mdPath, isExternalLink)})`);
|
||||
} else {
|
||||
snippet.appendText(isExternalLink ? uriString : escapeMarkdownLinkPath(mdPath));
|
||||
snippet.appendText((escapeMarkdownLinkPath(isExternalLink ? uriString : mdPath, isExternalLink)));
|
||||
}
|
||||
return snippet;
|
||||
}
|
||||
@@ -268,9 +268,9 @@ export function createUriListSnippet(
|
||||
const placeholderText = escapeBrackets(title) || options?.placeholderText || 'Alt text';
|
||||
const placeholderIndex = typeof options?.placeholderStartIndex !== 'undefined' ? options?.placeholderStartIndex + i : (placeholderValue === 0 ? undefined : placeholderValue);
|
||||
snippet.appendPlaceholder(placeholderText, placeholderIndex);
|
||||
snippet.appendText(`](${escapeMarkdownLinkPath(mdPath)})`);
|
||||
snippet.appendText(`](${escapeMarkdownLinkPath(mdPath, isExternalLink)})`);
|
||||
} else {
|
||||
snippet.appendText(escapeMarkdownLinkPath(mdPath));
|
||||
snippet.appendText(escapeMarkdownLinkPath(mdPath, isExternalLink));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -397,12 +397,12 @@ function escapeHtmlAttribute(attr: string): string {
|
||||
return encodeURI(attr).replaceAll('"', '"');
|
||||
}
|
||||
|
||||
function escapeMarkdownLinkPath(mdPath: string): string {
|
||||
function escapeMarkdownLinkPath(mdPath: string, isExternalLink: boolean): string {
|
||||
if (needsBracketLink(mdPath)) {
|
||||
return '<' + mdPath.replaceAll('<', '\\<').replaceAll('>', '\\>') + '>';
|
||||
}
|
||||
|
||||
return encodeURI(mdPath);
|
||||
return isExternalLink ? mdPath : encodeURI(mdPath);
|
||||
}
|
||||
|
||||
function escapeBrackets(value: string): string {
|
||||
|
||||
Reference in New Issue
Block a user