diff --git a/extensions/markdown-math/package.json b/extensions/markdown-math/package.json index 077c90d9686..71cb1028e6f 100644 --- a/extensions/markdown-math/package.json +++ b/extensions/markdown-math/package.json @@ -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" } } } diff --git a/extensions/markdown-math/package.nls.json b/extensions/markdown-math/package.nls.json index fe869a996d0..8e95dac52bb 100644 --- a/extensions/markdown-math/package.nls.json +++ b/extensions/markdown-math/package.nls.json @@ -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." } diff --git a/extensions/markdown-math/src/extension.ts b/extensions/markdown-math/src/extension.ts index cccd656f924..38fe52b3203 100644 --- a/extensions/markdown-math/src/extension.ts +++ b/extensions/markdown-math/src/extension.ts @@ -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('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;