mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 18:19:12 +01: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
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
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';
|
|
|
|
const styleHref = import.meta.url.replace(/katex.js$/, 'katex.min.css');
|
|
|
|
export function activate(ctx: {
|
|
getRenderer: (id: string) => any
|
|
}) {
|
|
const markdownItRenderer = ctx.getRenderer('markdownItRenderer');
|
|
|
|
const link = document.createElement('link');
|
|
link.rel = 'stylesheet';
|
|
link.classList.add('markdown-style');
|
|
link.href = styleHref;
|
|
document.head.append(link);
|
|
|
|
const style = document.createElement('style');
|
|
style.classList.add('markdown-style');
|
|
style.textContent = `
|
|
.katex-error {
|
|
color: var(--vscode-editorError-foreground);
|
|
}
|
|
`;
|
|
document.head.append(style);
|
|
|
|
const katex = require('@iktakahiro/markdown-it-katex');
|
|
markdownItRenderer.extendMarkdownIt((md: markdownIt.MarkdownIt) => {
|
|
return md.use(katex);
|
|
});
|
|
}
|