Skip to content

Commit

Permalink
🛠 #570 option math.enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhang committed Mar 22, 2020
1 parent 3532933 commit 7d7d9d9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@
"description": "%config.list.indentationSize.description%",
"scope": "resource"
},
"markdown.extension.math.enabled": {
"type": "boolean",
"default": true,
"description": "%config.math.enabled%"
},
"markdown.extension.orderedList.autoRenumber": {
"type": "boolean",
"default": true,
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"config.list.indentationSize.description": "Whether to use different indentation sizes on different contexts. (This also affects the generated TOC)",
"config.list.indentationSize.enumDescriptions.adaptive": "Use 2 spaces for unordered list and 3 for the ordered",
"config.list.indentationSize.enumDescriptions.inherit": "Use the configured tab size of the current document (see vscode status bar)",
"config.math.enabled": "Enable basic math support (with KaTeX)",
"config.preview.autoShowPreviewToSide.description": "Auto show preview to side",
"config.orderedList.marker.description": "Ordered list marker",
"config.orderedList.marker.enumDescriptions.one": "Always use `1.` as ordered list marker",
Expand Down
1 change: 1 addition & 0 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"config.list.indentationSize.description": "Markdown 列表的缩进量(包括目录列表的缩进大小)",
"config.list.indentationSize.enumDescriptions.adaptive": "无序列表中使用 2 空格,有序列表中使用 3 空格",
"config.list.indentationSize.enumDescriptions.inherit": "使用当前文档设置的缩进量(请查看 vscode 状态栏)",
"config.math.enabled": "启用基本的数学支持(由 KaTeX 提供)",
"config.preview.autoShowPreviewToSide.description": "自动在侧边栏显示预览",
"config.orderedList.marker.description": "有序列表标记",
"config.orderedList.marker.enumDescriptions.one": "总是使用 `1.` 作为有序列表标记",
Expand Down
30 changes: 19 additions & 11 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,26 @@ import { getNewFeatureMsg, showChangelog } from './util';
export function activate(context: ExtensionContext) {
activateMdExt(context);

// Make a deep copy as `macros` will be modified by KaTeX during initialization
let userMacros = JSON.parse(JSON.stringify(workspace.getConfiguration('markdown.extension.katex').get<object>('macros')));
let katexOptions = { throwOnError: false };
if (Object.keys(userMacros).length !== 0) {
katexOptions['macros'] = userMacros;
}
if (workspace.getConfiguration('markdown.extension.math').get<boolean>('enabled')) {
// Make a deep copy as `macros` will be modified by KaTeX during initialization
let userMacros = JSON.parse(JSON.stringify(workspace.getConfiguration('markdown.extension.katex').get<object>('macros')));
let katexOptions = { throwOnError: false };
if (Object.keys(userMacros).length !== 0) {
katexOptions['macros'] = userMacros;
}

return {
extendMarkdownIt(md) {
require('katex/contrib/mhchem/mhchem');
return md.use(require('markdown-it-task-lists'))
.use(require('@neilsustc/markdown-it-katex'), katexOptions);
return {
extendMarkdownIt(md) {
require('katex/contrib/mhchem/mhchem');
return md.use(require('markdown-it-task-lists'))
.use(require('@neilsustc/markdown-it-katex'), katexOptions);
}
}
} else {
return {
extendMarkdownIt(md) {
return md.use(require('markdown-it-task-lists'));
}
}
}
}
Expand Down

0 comments on commit 7d7d9d9

Please sign in to comment.