Files
azuredatastudio/extensions/markdown-math/notebook/katex.ts
Karl Burtram e7d3d047ec Merge from vscode merge-base (#22780)
* Revert "Revert "Merge from vscode merge-base (#22769)" (#22779)"

This reverts commit 47a1745180.

* Fix notebook download task

* Remove done call from extensions-ci
2023-04-19 21:48:46 -07:00

51 lines
1.8 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type * as markdownIt from 'markdown-it';
import type { RendererContext } from 'vscode-notebook-renderer';
const styleHref = import.meta.url.replace(/katex.js$/, 'katex.min.css');
export async function activate(ctx: RendererContext<void>) {
const markdownItRenderer = (await ctx.getRenderer('vscode.markdown-it-renderer')) as undefined | any;
if (!markdownItRenderer) {
throw new Error(`Could not load 'vscode.markdown-it-renderer'`);
}
// Add katex styles to be copied to shadow dom
const link = document.createElement('link');
link.rel = 'stylesheet';
link.classList.add('markdown-style');
link.href = styleHref;
document.head.append(link);
// Add same katex style to root document.
// This is needed for the font to be loaded correctly inside the shadow dom.
//
// Seems like https://bugs.chromium.org/p/chromium/issues/detail?id=336876
const linkHead = document.createElement('link');
linkHead.rel = 'stylesheet';
linkHead.href = styleHref;
document.head.appendChild(linkHead);
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');
const macros = {};
markdownItRenderer.extendMarkdownIt((md: markdownIt.MarkdownIt) => {
return md.use(katex, {
globalGroup: true,
enableBareBlocks: true,
macros
});
});
}