mirror of
https://github.com/microsoft/vscode.git
synced 2026-02-21 18:28:50 +00:00
* added support for markdown fenced math blocks * original markdownEngine.ts * Add fenced math block rendering to markdown-math * Update dependencies * custom parser for fenced math blocks * custom parser for fenced math blocks * reverted changes to extension.ts * reverted all changes from prior implementations * proper fence grammar implementation for math --------- Co-authored-by: Matt Bierner <matb@microsoft.com>
46 lines
1.5 KiB
TypeScript
46 lines
1.5 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 * as vscode from 'vscode';
|
|
|
|
declare function require(path: string): any;
|
|
|
|
const markdownMathSetting = 'markdown.math';
|
|
|
|
export function activate(context: vscode.ExtensionContext) {
|
|
function isEnabled(): boolean {
|
|
const config = vscode.workspace.getConfiguration('markdown');
|
|
return config.get<boolean>('math.enabled', true);
|
|
}
|
|
|
|
function getMacros(): { [key: string]: string } {
|
|
const config = vscode.workspace.getConfiguration('markdown');
|
|
return config.get<{ [key: string]: string }>('math.macros', {});
|
|
}
|
|
|
|
vscode.workspace.onDidChangeConfiguration(e => {
|
|
if (e.affectsConfiguration(markdownMathSetting)) {
|
|
vscode.commands.executeCommand('markdown.api.reloadPlugins');
|
|
}
|
|
}, undefined, context.subscriptions);
|
|
|
|
return {
|
|
extendMarkdownIt(md: any) {
|
|
if (isEnabled()) {
|
|
const katex = require('@vscode/markdown-it-katex').default;
|
|
const settingsMacros = getMacros();
|
|
const options = {
|
|
enableFencedBlocks: true,
|
|
globalGroup: true,
|
|
macros: { ...settingsMacros }
|
|
};
|
|
md.core.ruler.push('reset-katex-macros', () => {
|
|
options.macros = { ...settingsMacros };
|
|
});
|
|
return md.use(katex, options);
|
|
}
|
|
return md;
|
|
}
|
|
};
|
|
} |