提交 20654ccc 编写于 作者: M Matt Bierner

Marking IMarkdownString.value and isTrusted as readonly

上级 90b66c88
......@@ -7,23 +7,27 @@ import { equals } from 'vs/base/common/arrays';
import { UriComponents } from 'vs/base/common/uri';
export interface IMarkdownString {
value: string;
isTrusted?: boolean;
readonly value: string;
readonly isTrusted?: boolean;
uris?: { [href: string]: UriComponents };
}
export class MarkdownString implements IMarkdownString {
value: string;
isTrusted?: boolean;
private _value: string;
private _isTrusted: boolean;
constructor(value: string = '') {
this.value = value;
constructor(value: string = '', isTrusted = false) {
this._value = value;
this._isTrusted = isTrusted;
}
get value() { return this._value; }
get isTrusted() { return this._isTrusted; }
appendText(value: string): MarkdownString {
// escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
this.value += value
this._value += value
.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&')
.replace('\n', '\n\n');
......@@ -31,16 +35,16 @@ export class MarkdownString implements IMarkdownString {
}
appendMarkdown(value: string): MarkdownString {
this.value += value;
this._value += value;
return this;
}
appendCodeblock(langId: string, code: string): MarkdownString {
this.value += '\n```';
this.value += langId;
this.value += '\n';
this.value += code;
this.value += '\n```\n';
this._value += '\n```';
this._value += langId;
this._value += '\n';
this._value += code;
this._value += '\n```\n';
return this;
}
}
......
......@@ -44,8 +44,7 @@ function getHoverMessage(link: Link, useMetaKey: boolean): MarkdownString {
: nls.localize('links.navigate.kb.alt', "alt + click");
if (link.url) {
const hoverMessage = new MarkdownString().appendMarkdown(`[${label}](${link.url.toString()}) (${kb})`);
hoverMessage.isTrusted = true;
const hoverMessage = new MarkdownString('', true).appendMarkdown(`[${label}](${link.url.toString()}) (${kb})`);
return hoverMessage;
} else {
return new MarkdownString().appendText(`${label} (${kb})`);
......
......@@ -379,8 +379,8 @@ declare namespace monaco {
}
export interface IMarkdownString {
value: string;
isTrusted?: boolean;
readonly value: string;
readonly isTrusted?: boolean;
uris?: {
[href: string]: UriComponents;
};
......
......@@ -303,9 +303,7 @@ export namespace MarkdownString {
}
export function to(value: htmlContent.IMarkdownString): vscode.MarkdownString {
const ret = new htmlContent.MarkdownString(value.value);
ret.isTrusted = value.isTrusted;
return ret;
return new htmlContent.MarkdownString(value.value, value.isTrusted);
}
export function fromStrict(value: string | types.MarkdownString): undefined | string | htmlContent.IMarkdownString {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册