Skip to content

Commit 20654cc

Browse files
committed
Marking IMarkdownString.value and isTrusted as readonly
1 parent 90b66c8 commit 20654cc

4 files changed

Lines changed: 21 additions & 20 deletions

File tree

src/vs/base/common/htmlContent.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,44 @@ import { equals } from 'vs/base/common/arrays';
77
import { UriComponents } from 'vs/base/common/uri';
88

99
export interface IMarkdownString {
10-
value: string;
11-
isTrusted?: boolean;
10+
readonly value: string;
11+
readonly isTrusted?: boolean;
1212
uris?: { [href: string]: UriComponents };
1313
}
1414

1515
export class MarkdownString implements IMarkdownString {
1616

17-
value: string;
18-
isTrusted?: boolean;
17+
private _value: string;
18+
private _isTrusted: boolean;
1919

20-
constructor(value: string = '') {
21-
this.value = value;
20+
constructor(value: string = '', isTrusted = false) {
21+
this._value = value;
22+
this._isTrusted = isTrusted;
2223
}
2324

25+
get value() { return this._value; }
26+
get isTrusted() { return this._isTrusted; }
27+
2428
appendText(value: string): MarkdownString {
2529
// escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
26-
this.value += value
30+
this._value += value
2731
.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&')
2832
.replace('\n', '\n\n');
2933

3034
return this;
3135
}
3236

3337
appendMarkdown(value: string): MarkdownString {
34-
this.value += value;
38+
this._value += value;
3539
return this;
3640
}
3741

3842
appendCodeblock(langId: string, code: string): MarkdownString {
39-
this.value += '\n```';
40-
this.value += langId;
41-
this.value += '\n';
42-
this.value += code;
43-
this.value += '\n```\n';
43+
this._value += '\n```';
44+
this._value += langId;
45+
this._value += '\n';
46+
this._value += code;
47+
this._value += '\n```\n';
4448
return this;
4549
}
4650
}

src/vs/editor/contrib/links/links.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ function getHoverMessage(link: Link, useMetaKey: boolean): MarkdownString {
4444
: nls.localize('links.navigate.kb.alt', "alt + click");
4545

4646
if (link.url) {
47-
const hoverMessage = new MarkdownString().appendMarkdown(`[${label}](${link.url.toString()}) (${kb})`);
48-
hoverMessage.isTrusted = true;
47+
const hoverMessage = new MarkdownString('', true).appendMarkdown(`[${label}](${link.url.toString()}) (${kb})`);
4948
return hoverMessage;
5049
} else {
5150
return new MarkdownString().appendText(`${label} (${kb})`);

src/vs/monaco.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ declare namespace monaco {
379379
}
380380

381381
export interface IMarkdownString {
382-
value: string;
383-
isTrusted?: boolean;
382+
readonly value: string;
383+
readonly isTrusted?: boolean;
384384
uris?: {
385385
[href: string]: UriComponents;
386386
};

src/vs/workbench/api/common/extHostTypeConverters.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,7 @@ export namespace MarkdownString {
303303
}
304304

305305
export function to(value: htmlContent.IMarkdownString): vscode.MarkdownString {
306-
const ret = new htmlContent.MarkdownString(value.value);
307-
ret.isTrusted = value.isTrusted;
308-
return ret;
306+
return new htmlContent.MarkdownString(value.value, value.isTrusted);
309307
}
310308

311309
export function fromStrict(value: string | types.MarkdownString): undefined | string | htmlContent.IMarkdownString {

0 commit comments

Comments
 (0)