diff --git a/extensions/markdown/media/loading.js b/extensions/markdown/media/loading.js new file mode 100644 index 00000000000..38020f4e10a --- /dev/null +++ b/extensions/markdown/media/loading.js @@ -0,0 +1,26 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +(function () { + const unloadedStyles = []; + + window.onStyleLoadError = (event) => { + const source = event.target.dataset.source; + unloadedStyles.push(source); + }; + + window.addEventListener('load', () => { + if (!unloadedStyles.length) { + return; + } + const args = [unloadedStyles]; + window.parent.postMessage({ + command: 'did-click-link', + data: `command:_markdown.onPreviewStyleLoadError?${encodeURIComponent(JSON.stringify(args))}` + }, 'file://'); + }); +}()); \ No newline at end of file diff --git a/extensions/markdown/src/extension.ts b/extensions/markdown/src/extension.ts index e454e22879b..8e459df89a2 100644 --- a/extensions/markdown/src/extension.ts +++ b/extensions/markdown/src/extension.ts @@ -15,6 +15,8 @@ import { ExtensionContentSecurityPolicyArbiter, PreviewSecuritySelector } from ' import { MDDocumentContentProvider, getMarkdownUri, isMarkdownFile } from './previewContentProvider'; import { TableOfContentsProvider } from './tableOfContentsProvider'; import { Logger } from "./logger"; +import * as nls from 'vscode-nls'; +const localize = nls.loadMessageBundle(); interface IPackageInfo { name: string; @@ -166,6 +168,10 @@ export function activate(context: vscode.ExtensionContext) { previewSecuritySelector.showSecutitySelectorForWorkspace(resource ? vscode.Uri.parse(resource).query : undefined); })); + context.subscriptions.push(vscode.commands.registerCommand('_markdown.onPreviewStyleLoadError', (resources: string[]) => { + vscode.window.showWarningMessage(localize('onPreviewStyleLoadError', "Could not load 'markdown.styles': {0}", resources.join(', '))); + })); + context.subscriptions.push(vscode.workspace.onDidSaveTextDocument(document => { if (isMarkdownFile(document)) { const uri = getMarkdownUri(document.uri); diff --git a/extensions/markdown/src/previewContentProvider.ts b/extensions/markdown/src/previewContentProvider.ts index 65cf0693354..82088d4b4f5 100644 --- a/extensions/markdown/src/previewContentProvider.ts +++ b/extensions/markdown/src/previewContentProvider.ts @@ -166,7 +166,7 @@ export class MDDocumentContentProvider implements vscode.TextDocumentContentProv private computeCustomStyleSheetIncludes(uri: vscode.Uri): string { if (this.config.styles && Array.isArray(this.config.styles)) { return this.config.styles.map((style) => { - return ``; + return ``; }).join('\n'); } return ''; @@ -238,6 +238,7 @@ export class MDDocumentContentProvider implements vscode.TextDocumentContentProv ${csp} + ${this.getStyles(uri, nonce)}