diff --git a/extensions/markdown-language-features/notebook/index.ts b/extensions/markdown-language-features/notebook/index.ts index 2b6c893e3a13db..7bda590e9e34b3 100644 --- a/extensions/markdown-language-features/notebook/index.ts +++ b/extensions/markdown-language-features/notebook/index.ts @@ -3,8 +3,8 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -const MarkdownIt: typeof import('markdown-it') = require('markdown-it'); import * as DOMPurify from 'dompurify'; +import MarkdownIt from 'markdown-it'; import type * as MarkdownItToken from 'markdown-it/lib/token'; import type { ActivationFunction } from 'vscode-notebook-renderer'; @@ -13,9 +13,15 @@ const sanitizerOptions: DOMPurify.Config = { }; export const activate: ActivationFunction = (ctx) => { - const markdownIt = new MarkdownIt({ + const markdownIt: MarkdownIt = new MarkdownIt({ html: true, linkify: true, + highlight: (str: string, lang?: string) => { + if (lang) { + return `${markdownIt.utils.escapeHtml(str)}`; + } + return `${markdownIt.utils.escapeHtml(str)}`; + } }); markdownIt.linkify.set({ fuzzyLink: false }); diff --git a/extensions/markdown-language-features/notebook/tsconfig.json b/extensions/markdown-language-features/notebook/tsconfig.json index b90051ec35d0a5..a94411a1e520c6 100644 --- a/extensions/markdown-language-features/notebook/tsconfig.json +++ b/extensions/markdown-language-features/notebook/tsconfig.json @@ -4,6 +4,7 @@ "outDir": "./dist/", "jsx": "react", "moduleResolution": "Node", + "allowSyntheticDefaultImports": true, "module": "es2020", "lib": [ "es2018", diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts index a50277d830a1ce..d7fc86b2e6c081 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts @@ -15,6 +15,10 @@ import { isMacintosh, isWeb } from 'vs/base/common/platform'; import { dirname, joinPath } from 'vs/base/common/resources'; import { URI } from 'vs/base/common/uri'; import * as UUID from 'vs/base/common/uuid'; +import { TokenizationRegistry } from 'vs/editor/common/modes'; +import { generateTokensCSSForColorMap } from 'vs/editor/common/modes/supports/tokenization'; +import { tokenizeToString } from 'vs/editor/common/modes/textToHtmlTokenizer'; +import { IModeService } from 'vs/editor/common/services/modeService'; import * as nls from 'vs/nls'; import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem'; import { IMenuService, MenuId } from 'vs/platform/actions/common/actions'; @@ -36,7 +40,7 @@ import { INotebookRendererInfo, RendererMessagingSpec } from 'vs/workbench/contr import { INotebookKernel } from 'vs/workbench/contrib/notebook/common/notebookKernelService'; import { IScopedRendererMessaging } from 'vs/workbench/contrib/notebook/common/notebookRendererMessagingService'; import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService'; -import { IWebviewService, WebviewContentPurpose, IWebviewElement } from 'vs/workbench/contrib/webview/browser/webview'; +import { IWebviewElement, IWebviewService, WebviewContentPurpose } from 'vs/workbench/contrib/webview/browser/webview'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { FromWebviewMessage, IAckOutputHeight, IClickedDataUrlMessage, IContentWidgetTopRequest, IControllerPreload, ICreationRequestMessage, IMarkupCellInitialization, ToWebviewMessage } from './webviewMessages'; @@ -131,6 +135,7 @@ export class BackLayerWebView extends Disposable { @ITelemetryService private readonly telemetryService: ITelemetryService, @IWorkspaceTrustManagementService private readonly workspaceTrustManagementService: IWorkspaceTrustManagementService, @IConfigurationService private readonly configurationService: IConfigurationService, + @IModeService private readonly modeService: IModeService, ) { super(); @@ -163,6 +168,13 @@ export class BackLayerWebView extends Disposable { isTrusted: e, }); })); + + this._register(TokenizationRegistry.onDidChange(() => { + this._sendMessageToWebview({ + type: 'tokenizedStylesChanged', + css: getTokenizationCss(), + }); + })); } updateOptions(options: { @@ -353,8 +365,8 @@ export class BackLayerWebView extends Disposable { tbody th { font-weight: normal; } - +