mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 00:59:03 +01:00
* Render markdown preview cells inside a shadow dom Fixes #119971 This moves all markdown previews into shadow doms. This lets us prevent styles from outside the preview leak into the preview, and also prevents styles from the preview leak out into the rest of the notebook * Use composedPath for handling events in webviews This lets us handle clicks triggered inside of a shadow dom
29 lines
962 B
TypeScript
29 lines
962 B
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
import type * as markdownIt from 'markdown-it';
|
|
|
|
declare const extendMarkdownIt: undefined | (
|
|
(f: (md: markdownIt.MarkdownIt) => void) => void
|
|
);
|
|
|
|
const styleHref = (document.currentScript as any).src.replace(/katex.js$/, 'katex.min.css');
|
|
|
|
const link = document.createElement('link');
|
|
link.rel = 'stylesheet';
|
|
link.classList.add('markdown-style');
|
|
link.href = styleHref;
|
|
|
|
document.head.append(link);
|
|
|
|
(function () {
|
|
const katex = require('@iktakahiro/markdown-it-katex');
|
|
if (typeof extendMarkdownIt !== 'undefined') {
|
|
|
|
extendMarkdownIt((md: markdownIt.MarkdownIt) => {
|
|
md.use(katex);
|
|
});
|
|
}
|
|
}());
|