mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-28 04:23:32 +01:00
Initial support for syntax highlighting md code blocks in notebooks
For #136693
This commit is contained in:
@@ -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<void> = (ctx) => {
|
||||
const markdownIt = new MarkdownIt({
|
||||
const markdownIt: MarkdownIt = new MarkdownIt({
|
||||
html: true,
|
||||
linkify: true,
|
||||
highlight: (str: string, lang?: string) => {
|
||||
if (lang) {
|
||||
return `<code class="vscode-code-block" data-vscode-code-block-lang="${markdownIt.utils.escapeHtml(lang)}">${markdownIt.utils.escapeHtml(str)}</code>`;
|
||||
}
|
||||
return `<code>${markdownIt.utils.escapeHtml(str)}</code>`;
|
||||
}
|
||||
});
|
||||
markdownIt.linkify.set({ fuzzyLink: false });
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"outDir": "./dist/",
|
||||
"jsx": "react",
|
||||
"moduleResolution": "Node",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"module": "es2020",
|
||||
"lib": [
|
||||
"es2018",
|
||||
|
||||
Reference in New Issue
Block a user