Render markdown preview cells inside a shadow dom (#120137)

* 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
This commit is contained in:
Matt Bierner
2021-03-30 14:17:15 -07:00
committed by GitHub
parent 268ac6e3df
commit d4412e708a
6 changed files with 194 additions and 148 deletions

View File

@@ -24,5 +24,10 @@ type extendMarkdownItFnType = (
notebook.onDidCreateMarkdown(({ element, content }: any) => {
const rendered = markdownIt.render(content);
element.innerHTML = rendered;
// Insert styles into markdown preview shadow dom so that they are applied
for (const markdownStyleNode of document.getElementsByClassName('markdown-style')) {
element.appendChild(markdownStyleNode.cloneNode(true));
}
});
}());

View File

@@ -0,0 +1,12 @@
{
"extends": "../../shared.tsconfig.json",
"compilerOptions": {
"outDir": "./dist/",
"jsx": "react",
"lib": [
"es2018",
"DOM",
"DOM.Iterable"
]
}
}