Skip to content

Commit 59ccb98

Browse files
committed
Unescape Markdown Escapes inside of a link
Fixes microsoft#14968 **Bug** Due to markedjs/marked#829, markdown escapes inside of links are currently not rendered properly. This also can effect regular text that contains characters that are escaped when we convert them to markdown text. **Fix** For links, remove markdown escapes before rendering them.
1 parent d167728 commit 59ccb98

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/vs/base/browser/htmlContentRenderer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import DOM = require('vs/base/browser/dom');
99
import { defaultGenerator } from 'vs/base/common/idGenerator';
1010
import { escape } from 'vs/base/common/strings';
1111
import { TPromise } from 'vs/base/common/winjs.base';
12-
import { IHTMLContentElement, MarkedString } from 'vs/base/common/htmlContent';
12+
import { IHTMLContentElement, MarkedString, removeMarkdownEscapes } from 'vs/base/common/htmlContent';
1313
import { marked } from 'vs/base/common/marked/marked';
1414
import { IMouseEvent } from 'vs/base/browser/mouseEvent';
1515

@@ -127,6 +127,9 @@ function _renderHtml(content: IHTMLContentElement, options: RenderOptions = {}):
127127
return '<img ' + attributes.join(' ') + '>';
128128
};
129129
renderer.link = (href, title, text): string => {
130+
// Remove markdown escapes in href and title. Workaround for https://github.com/chjj/marked/issues/829
131+
title = removeMarkdownEscapes(title);
132+
href = removeMarkdownEscapes(href);
130133
return `<a href="#" data-href="${href}" title="${title || text}">${text}</a>`;
131134
};
132135
renderer.paragraph = (text): string => {

src/vs/base/common/htmlContent.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ export function textToMarkedString(text: string): MarkedString {
7171
return text.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&'); // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
7272
}
7373

74+
export function removeMarkdownEscapes(text: string): string {
75+
if (!text) {
76+
return text;
77+
}
78+
return text.replace(/\\([\\`*_{}[\]()#+\-.!])/g, '$1');
79+
}
7480

7581
export interface IHTMLContentElement {
7682
/**

0 commit comments

Comments
 (0)