Skip to content

Commit 4e23537

Browse files
committed
htmlContent.textToMarkedString: Convert plainText to MarkedString
1 parent 4fae08e commit 4e23537

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/vs/base/common/htmlContent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ function markedStringEqual(a:MarkedString, b:MarkedString): boolean {
6767
);
6868
}
6969

70-
export function textAsCodeBlock(text: string) : MarkedString {
71-
return { language: 'string', value: text };
70+
export function textToMarkedString(text: string) : MarkedString {
71+
return text.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&'); // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
7272
}
7373

7474

src/vs/editor/common/services/modelServiceImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as nls from 'vs/nls';
88
import network = require('vs/base/common/network');
99
import Event, {Emitter} from 'vs/base/common/event';
1010
import {EmitterEvent} from 'vs/base/common/eventEmitter';
11-
import {MarkedString, textAsCodeBlock} from 'vs/base/common/htmlContent';
11+
import {MarkedString, textToMarkedString} from 'vs/base/common/htmlContent';
1212
import {IDisposable} from 'vs/base/common/lifecycle';
1313
import Severity from 'vs/base/common/severity';
1414
import URI from 'vs/base/common/uri';
@@ -147,7 +147,7 @@ class ModelMarkerHandler {
147147
if (source) {
148148
message = nls.localize('sourceAndDiagMessage', "[{0}] {1}", source, message);
149149
}
150-
hoverMessage = [textAsCodeBlock(message)];
150+
hoverMessage = [textToMarkedString(message)];
151151
}
152152

153153
return {

src/vs/editor/contrib/goToDeclaration/browser/goToDeclaration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'vs/css!./goToDeclaration';
99
import * as nls from 'vs/nls';
1010
import {Throttler} from 'vs/base/common/async';
1111
import {onUnexpectedError} from 'vs/base/common/errors';
12-
import {MarkedString, textAsCodeBlock} from 'vs/base/common/htmlContent';
12+
import {MarkedString, textToMarkedString} from 'vs/base/common/htmlContent';
1313
import {KeyCode, KeyMod} from 'vs/base/common/keyCodes';
1414
import * as platform from 'vs/base/common/platform';
1515
import Severity from 'vs/base/common/severity';
@@ -388,7 +388,7 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
388388
value: text
389389
};
390390
} else {
391-
hoverMessage = textAsCodeBlock(text);
391+
hoverMessage = textToMarkedString(text);
392392
}
393393
}
394394

src/vs/editor/contrib/hover/browser/modesContentHover.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {ICodeEditor} from 'vs/editor/browser/editorBrowser';
2121
import {getHover} from '../common/hover';
2222
import {HoverOperation, IHoverComputer} from './hoverOperation';
2323
import {ContentHoverWidget} from './hoverWidgets';
24-
import {textAsCodeBlock, MarkedString} from 'vs/base/common/htmlContent';
24+
import {textToMarkedString, MarkedString} from 'vs/base/common/htmlContent';
2525

2626
class ModesContentComputer implements IHoverComputer<Hover[]> {
2727

@@ -113,7 +113,7 @@ class ModesContentComputer implements IHoverComputer<Hover[]> {
113113
private _getLoadingMessage(): Hover {
114114
return {
115115
range: this._range,
116-
contents: [textAsCodeBlock(nls.localize('modesContentHover.loading', "Loading..."))]
116+
contents: [textToMarkedString(nls.localize('modesContentHover.loading', "Loading..."))]
117117
};
118118
}
119119
}

0 commit comments

Comments
 (0)