Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MarkdownString

Human-readable text that supports formatting via the markdown syntax.

Rendering of theme icons via the $(<name>)-syntax is supported when the supportThemeIcons is set to true.

Rendering of embedded html is supported when supportHtml is set to true.

Hierarchy

  • MarkdownString

Index

Constructors(1)

constructor

  • new MarkdownString(value?: string, supportThemeIcons?: boolean): MarkdownString
  • Creates a new markdown string with the given value.

    Parameters

    • Optional value: string

      Optional, initial value.

    • Optional supportThemeIcons: boolean

      Optional, Specifies whether ThemeIcons are supported within the MarkdownString.

    Returns MarkdownString

Properties(5)

value

value: string

The markdown string.

Optional isTrusted

isTrusted: boolean | { enabledCommands: readonly string[] }

Indicates that this markdown string is from a trusted source. Only trusted markdown supports links that execute commands, e.g. [Run it](command:myCommandId).

Defaults to false (commands are disabled).

Optional supportThemeIcons

supportThemeIcons: boolean

Indicates that this markdown string can contain ThemeIcons, e.g. $(zap).

Optional supportHtml

supportHtml: boolean

Indicates that this markdown string can contain raw html tags. Defaults to false.

When supportHtml is false, the markdown renderer will strip out any raw html tags that appear in the markdown text. This means you can only use markdown syntax for rendering.

When supportHtml is true, the markdown render will also allow a safe subset of html tags and attributes to be rendered. See https://github.com/microsoft/vscode/blob/6d2920473c6f13759c978dd89104c4270a83422d/src/vs/base/browser/markdownRenderer.ts#L296 for a list of all supported tags and attributes.

Optional baseUri

baseUri: Uri

Uri that relative paths are resolved relative to.

If the baseUri ends with /, it is considered a directory and relative paths in the markdown are resolved relative to that directory:

const md = new vscode.MarkdownString(`[link](./file.js)`);
md.baseUri = vscode.Uri.file('/path/to/dir/');
// Here 'link' in the rendered markdown resolves to '/path/to/dir/file.js'

If the baseUri is a file, relative paths in the markdown are resolved relative to the parent dir of that file:

const md = new vscode.MarkdownString(`[link](./file.js)`);
md.baseUri = vscode.Uri.file('/path/to/otherFile.js');
// Here 'link' in the rendered markdown resolves to '/path/to/file.js'

Methods(3)

appendText

  • Appends and escapes the given string to this markdown string.

    Parameters

    • value: string

      Plain text.

    Returns MarkdownString

appendMarkdown

appendCodeblock

Generated by TypeDoc. Maintained by 洛竹