Initial support for syntax highlighting md code blocks in notebooks

For #136693
This commit is contained in:
Matt Bierner
2021-11-08 11:59:44 -08:00
parent 0a8e75411e
commit 5e6d0e1cbb
5 changed files with 108 additions and 5 deletions

View File

@@ -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 });

View File

@@ -4,6 +4,7 @@
"outDir": "./dist/",
"jsx": "react",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true,
"module": "es2020",
"lib": [
"es2018",