mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-11 18:41:06 -06:00
This implements the api described in #123540. Major points: - Instead of having the `markdown-it` renderer pull it its dependencies, instead the dependencies can call `getRenderer` to import the object returned by the `markdown-it` renderer - We try to detect if a renderer is using the old or new api. Old renderers are still run as globals while new ones are loaded with `import` - I have only hooked up the new API for markdown renderers so far
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
const MarkdownIt = require('markdown-it');
|
|
|
|
export function activate() {
|
|
let markdownIt = new MarkdownIt({
|
|
html: true
|
|
});
|
|
|
|
return {
|
|
renderCell: (_id: string, context: { element: HTMLElement, value: string }) => {
|
|
const rendered = markdownIt.render(context.value);
|
|
context.element.innerHTML = rendered;
|
|
|
|
// Insert styles into markdown preview shadow dom so that they are applied
|
|
for (const markdownStyleNode of document.getElementsByClassName('markdown-style')) {
|
|
context.element.insertAdjacentElement('beforebegin', markdownStyleNode.cloneNode(true) as Element);
|
|
}
|
|
},
|
|
extendMarkdownIt: (f: (md: typeof markdownIt) => void) => {
|
|
f(markdownIt);
|
|
}
|
|
};
|
|
}
|