mirror of
https://github.com/Microsoft/vscode
synced 2024-10-01 08:50:48 +00:00
parent
ffe64dab3c
commit
2929ec4996
|
@ -80,6 +80,13 @@
|
|||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "%config.markdown.math.enabled%"
|
||||
},
|
||||
"markdown.math.macros": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "type": "string" },
|
||||
"default": {},
|
||||
"description": "%config.markdown.math.macros%",
|
||||
"scope": "resource"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"displayName": "Markdown Math",
|
||||
"description": "Adds math support to Markdown in notebooks.",
|
||||
"config.markdown.math.enabled": "Enable/disable rendering math in the built-in Markdown preview."
|
||||
"config.markdown.math.enabled": "Enable/disable rendering math in the built-in Markdown preview.",
|
||||
"config.markdown.math.macros": "A collection of custom macros. Each macro is a key-value pair where the key is a new command name and the value is the expansion of the macro."
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import * as vscode from 'vscode';
|
|||
|
||||
declare function require(path: string): any;
|
||||
|
||||
const enabledSetting = 'markdown.math.enabled';
|
||||
const markdownMathSetting = 'markdown.math';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
function isEnabled(): boolean {
|
||||
|
@ -14,8 +14,13 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
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(enabledSetting)) {
|
||||
if (e.affectsConfiguration(markdownMathSetting)) {
|
||||
vscode.commands.executeCommand('markdown.api.reloadPlugins');
|
||||
}
|
||||
}, undefined, context.subscriptions);
|
||||
|
@ -24,8 +29,11 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
extendMarkdownIt(md: any) {
|
||||
if (isEnabled()) {
|
||||
const katex = require('@vscode/markdown-it-katex');
|
||||
const options = { globalGroup: true, macros: {} };
|
||||
md.core.ruler.push('reset-katex-macros', () => { options.macros = {}; });
|
||||
const settingsMacros = getMacros();
|
||||
const options = { globalGroup: true, macros: { ...settingsMacros } };
|
||||
md.core.ruler.push('reset-katex-macros', () => {
|
||||
options.macros = { ...settingsMacros };
|
||||
});
|
||||
return md.use(katex, options);
|
||||
}
|
||||
return md;
|
||||
|
|
Loading…
Reference in a new issue