Skip to content

Commit 2929ec4

Browse files
authored
Add macros entry to markdown-math configuration (microsoft#180458)
section.
1 parent ffe64da commit 2929ec4

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

extensions/markdown-math/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@
8080
"type": "boolean",
8181
"default": true,
8282
"description": "%config.markdown.math.enabled%"
83+
},
84+
"markdown.math.macros": {
85+
"type": "object",
86+
"additionalProperties": { "type": "string" },
87+
"default": {},
88+
"description": "%config.markdown.math.macros%",
89+
"scope": "resource"
8390
}
8491
}
8592
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"displayName": "Markdown Math",
33
"description": "Adds math support to Markdown in notebooks.",
4-
"config.markdown.math.enabled": "Enable/disable rendering math in the built-in Markdown preview."
4+
"config.markdown.math.enabled": "Enable/disable rendering math in the built-in Markdown preview.",
5+
"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."
56
}

extensions/markdown-math/src/extension.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@ import * as vscode from 'vscode';
66

77
declare function require(path: string): any;
88

9-
const enabledSetting = 'markdown.math.enabled';
9+
const markdownMathSetting = 'markdown.math';
1010

1111
export function activate(context: vscode.ExtensionContext) {
1212
function isEnabled(): boolean {
1313
const config = vscode.workspace.getConfiguration('markdown');
1414
return config.get<boolean>('math.enabled', true);
1515
}
1616

17+
function getMacros(): { [key: string]: string } {
18+
const config = vscode.workspace.getConfiguration('markdown');
19+
return config.get<{ [key: string]: string }>('math.macros', {});
20+
}
21+
1722
vscode.workspace.onDidChangeConfiguration(e => {
18-
if (e.affectsConfiguration(enabledSetting)) {
23+
if (e.affectsConfiguration(markdownMathSetting)) {
1924
vscode.commands.executeCommand('markdown.api.reloadPlugins');
2025
}
2126
}, undefined, context.subscriptions);
@@ -24,8 +29,11 @@ export function activate(context: vscode.ExtensionContext) {
2429
extendMarkdownIt(md: any) {
2530
if (isEnabled()) {
2631
const katex = require('@vscode/markdown-it-katex');
27-
const options = { globalGroup: true, macros: {} };
28-
md.core.ruler.push('reset-katex-macros', () => { options.macros = {}; });
32+
const settingsMacros = getMacros();
33+
const options = { globalGroup: true, macros: { ...settingsMacros } };
34+
md.core.ruler.push('reset-katex-macros', () => {
35+
options.macros = { ...settingsMacros };
36+
});
2937
return md.use(katex, options);
3038
}
3139
return md;

0 commit comments

Comments
 (0)