Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/markdown-math/src/extension.ts
4772 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
import * as vscode from 'vscode';
6
7
declare function require(path: string): any;
8
9
const markdownMathSetting = 'markdown.math';
10
11
export function activate(context: vscode.ExtensionContext) {
12
function isEnabled(): boolean {
13
const config = vscode.workspace.getConfiguration('markdown');
14
return config.get<boolean>('math.enabled', true);
15
}
16
17
function getMacros(): { [key: string]: string } {
18
const config = vscode.workspace.getConfiguration('markdown');
19
return config.get<{ [key: string]: string }>('math.macros', {});
20
}
21
22
vscode.workspace.onDidChangeConfiguration(e => {
23
if (e.affectsConfiguration(markdownMathSetting)) {
24
vscode.commands.executeCommand('markdown.api.reloadPlugins');
25
}
26
}, undefined, context.subscriptions);
27
28
return {
29
extendMarkdownIt(md: any) {
30
if (isEnabled()) {
31
const katex = require('@vscode/markdown-it-katex').default;
32
const settingsMacros = getMacros();
33
const options = {
34
enableFencedBlocks: true,
35
globalGroup: true,
36
macros: { ...settingsMacros }
37
};
38
md.core.ruler.push('reset-katex-macros', () => {
39
options.macros = { ...settingsMacros };
40
});
41
return md.use(katex, options);
42
}
43
return md;
44
}
45
};
46
}
47