Skip to content

Commit

Permalink
fix(plugin-markdown-math): fix mhchem for katex
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Jan 25, 2025
1 parent a2031ec commit 87af20a
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 100 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"mathjax",
"mdit",
"meteorlxy",
"mhchem",
"nord",
"npmmirror",
"nprogress",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
"@rollup/plugin-commonjs": "^28.0.2",
"@rollup/plugin-node-resolve": "^16.0.0",
"@types/node": "^22.10.10",
"@types/webpack-env": "^1.18.5",
"@types/webpack-env": "^1.18.6",
"@vitest/coverage-istanbul": "3.0.4",
"conventional-changelog-cli": "^5.0.0",
"cpx2": "^8.0.0",
"cross-env": "^7.0.3",
"eslint": "^9.18.0",
"eslint": "^9.19.0",
"eslint-config-vuepress": "^5.2.4",
"http-server": "^14.1.1",
"husky": "^9.1.7",
Expand Down
2 changes: 1 addition & 1 deletion plugins/markdown/plugin-markdown-math/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"style": "sass src:lib --embed-sources --style=compressed --pkg-importer=node"
},
"dependencies": {
"@mdit/plugin-katex-slim": "^0.16.2",
"@mdit/plugin-katex-slim": "^0.16.7",
"@mdit/plugin-mathjax-slim": "^0.16.0",
"@types/markdown-it": "^14.1.2",
"@vuepress/helper": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { MarkdownItKatexOptions } from '@mdit/plugin-katex-slim'
import { katex } from '@mdit/plugin-katex-slim'
import { katex, loadMhchem } from '@mdit/plugin-katex-slim'
import { createMathjaxInstance, mathjax } from '@mdit/plugin-mathjax-slim'
import { addCustomElement, isModuleAvailable } from '@vuepress/helper'
import type { Plugin } from 'vuepress/core'
Expand Down Expand Up @@ -65,7 +65,7 @@ export const markdownMathPlugin = ({
}
},

extendsMarkdown: (md) => {
extendsMarkdown: async (md) => {
if (mathRenderer === 'mathjax') {
md.use(mathjax, mathjaxInstance)
// Reset mathjax style in each render
Expand All @@ -81,6 +81,10 @@ export const markdownMathPlugin = ({
}
})
} else {
if ((options as MarkdownKatexPluginOptions).mhchem) {
await loadMhchem()
}

md.use<MarkdownItKatexOptions<MarkdownEnv>>(katex, {
logger: (errorCode, errorMsg, token, { filePathRelative }) => {
// Ignore this error
Expand All @@ -101,7 +105,6 @@ export const markdownMathPlugin = ({
}`,
)
},
macros: {},
...(options as Omit<MarkdownKatexPluginOptions, 'type'>),
transformer: (content) => content.replace(/^(<[a-z]+ )/g, '$1v-pre '),
})
Expand Down
5 changes: 5 additions & 0 deletions plugins/markdown/plugin-markdown-math/src/node/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export interface MarkdownKatexPluginOptions
extends Omit<MarkdownItKatexOptions, 'transformer'> {
type?: 'katex'

/**
* Whether enable mhchem plugin
*/
mhchem?: boolean

/**
* Whether enable copy plugin
*
Expand Down
2 changes: 1 addition & 1 deletion plugins/markdown/plugin-markdown-stylize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"dependencies": {
"@mdit/plugin-align": "^0.16.0",
"@mdit/plugin-attrs": "^0.16.2",
"@mdit/plugin-attrs": "^0.16.7",
"@mdit/plugin-mark": "^0.16.0",
"@mdit/plugin-spoiler": "^0.16.0",
"@mdit/plugin-stylize": "^0.16.0",
Expand Down
2 changes: 1 addition & 1 deletion plugins/markdown/plugin-revealjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"dependencies": {
"@mdit/plugin-uml": "^0.16.0",
"@types/markdown-it": "^14.1.2",
"@types/reveal.js": "^5.0.4",
"@types/reveal.js": "^5.0.5",
"@vuepress/helper": "workspace:*",
"@vueuse/core": "^12.5.0",
"reveal.js": "^5.1.0",
Expand Down
Loading

0 comments on commit 87af20a

Please sign in to comment.