Skip to content

Commit 4c5336d

Browse files
authored
Skip encoding of markdown links (#200588)
Fixes #200213 This encoding should no longer be needed now that we can smartly insert angle bracket links
1 parent c2ed45b commit 4c5336d

File tree

1 file changed

+14
-16
lines changed
  • extensions/markdown-language-features/src/languageFeatures/copyFiles

1 file changed

+14
-16
lines changed

extensions/markdown-language-features/src/languageFeatures/copyFiles/shared.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ export function appendToLinkSnippet(
189189
title: string,
190190
link: string,
191191
placeholderValue: number,
192-
isExternalLink: boolean,
192+
_isExternalLink: boolean,
193193
): void {
194194
snippet.appendText('[');
195195
snippet.appendPlaceholder(escapeBrackets(title) || 'Title', placeholderValue);
196-
snippet.appendText(`](${escapeMarkdownLinkPath(link, isExternalLink)})`);
196+
snippet.appendText(`](${escapeMarkdownLinkPath(link)})`);
197197
}
198198

199199
export function createUriListSnippet(
@@ -238,17 +238,15 @@ export function createUriListSnippet(
238238
snippet.appendPlaceholder(escapeBrackets(title) || 'Title', placeholderValue);
239239
snippet.appendText('"></audio>');
240240
} else if (insertAsMedia) {
241-
if (insertAsMedia) {
242-
insertedImageCount++;
243-
if (pasteAsMarkdownLink) {
244-
snippet.appendText('![');
245-
const placeholderText = escapeBrackets(title) || options?.placeholderText || 'Alt text';
246-
const placeholderIndex = typeof options?.placeholderStartIndex !== 'undefined' ? options?.placeholderStartIndex + i : (placeholderValue === 0 ? undefined : placeholderValue);
247-
snippet.appendPlaceholder(placeholderText, placeholderIndex);
248-
snippet.appendText(`](${escapeMarkdownLinkPath(mdPath, isExternalLink)})`);
249-
} else {
250-
snippet.appendText(escapeMarkdownLinkPath(mdPath, isExternalLink));
251-
}
241+
insertedImageCount++;
242+
if (pasteAsMarkdownLink) {
243+
snippet.appendText('![');
244+
const placeholderText = escapeBrackets(title) || options?.placeholderText || 'Alt text';
245+
const placeholderIndex = typeof options?.placeholderStartIndex !== 'undefined' ? options?.placeholderStartIndex + i : (placeholderValue === 0 ? undefined : placeholderValue);
246+
snippet.appendPlaceholder(placeholderText, placeholderIndex);
247+
snippet.appendText(`](${escapeMarkdownLinkPath(mdPath)})`);
248+
} else {
249+
snippet.appendText(escapeMarkdownLinkPath(mdPath));
252250
}
253251
} else {
254252
insertedLinkCount++;
@@ -371,20 +369,20 @@ function escapeHtmlAttribute(attr: string): string {
371369
return encodeURI(attr).replaceAll('"', '&quot;');
372370
}
373371

374-
function escapeMarkdownLinkPath(mdPath: string, isExternalLink: boolean): string {
372+
function escapeMarkdownLinkPath(mdPath: string): string {
375373
if (needsBracketLink(mdPath)) {
376374
return '<' + mdPath.replaceAll('<', '\\<').replaceAll('>', '\\>') + '>';
377375
}
378376

379-
return isExternalLink ? mdPath : encodeURI(mdPath);
377+
return mdPath;
380378
}
381379

382380
function escapeBrackets(value: string): string {
383381
value = value.replace(/[\[\]]/g, '\\$&'); // CodeQL [SM02383] The Markdown is fully sanitized after being rendered.
384382
return value;
385383
}
386384

387-
function needsBracketLink(mdPath: string) {
385+
function needsBracketLink(mdPath: string): boolean {
388386
// Links with whitespace or control characters must be enclosed in brackets
389387
if (mdPath.startsWith('<') || /\s|[\u007F\u0000-\u001f]/.test(mdPath)) {
390388
return true;

0 commit comments

Comments
 (0)