diff --git a/extensions/markdown/src/previewContentProvider.ts b/extensions/markdown/src/previewContentProvider.ts index 7ef099a8624..6a65997b19f 100644 --- a/extensions/markdown/src/previewContentProvider.ts +++ b/extensions/markdown/src/previewContentProvider.ts @@ -20,14 +20,12 @@ export function getMarkdownUri(uri: vscode.Uri) { export class MDDocumentContentProvider implements vscode.TextDocumentContentProvider { private _onDidChange = new vscode.EventEmitter(); - private _waiting: boolean; + private _waiting: boolean = false; constructor( private engine: MarkdownEngine, private context: vscode.ExtensionContext - ) { - this._waiting = false; - } + ) { } private getMediaPath(mediaFile: string): string { return vscode.Uri.file(this.context.asAbsolutePath(path.join('media', mediaFile))).toString(); @@ -38,27 +36,28 @@ export class MDDocumentContentProvider implements vscode.TextDocumentContentProv } private fixHref(resource: vscode.Uri, href: string): string { - if (href) { - // Use href if it is already an URL - if (vscode.Uri.parse(href).scheme) { - return href; - } - - // Use href as file URI if it is absolute - if (this.isAbsolute(href)) { - return vscode.Uri.file(href).toString(); - } - - // use a workspace relative path if there is a workspace - let rootPath = vscode.workspace.rootPath; - if (rootPath) { - return vscode.Uri.file(path.join(rootPath, href)).toString(); - } - - // otherwise look relative to the markdown file - return vscode.Uri.file(path.join(path.dirname(resource.fsPath), href)).toString(); + if (!href) { + return href; } - return href; + + // Use href if it is already an URL + if (vscode.Uri.parse(href).scheme) { + return href; + } + + // Use href as file URI if it is absolute + if (this.isAbsolute(href)) { + return vscode.Uri.file(href).toString(); + } + + // use a workspace relative path if there is a workspace + let rootPath = vscode.workspace.rootPath; + if (rootPath) { + return vscode.Uri.file(path.join(rootPath, href)).toString(); + } + + // otherwise look relative to the markdown file + return vscode.Uri.file(path.join(path.dirname(resource.fsPath), href)).toString(); } private computeCustomStyleSheetIncludes(uri: vscode.Uri): string {