From e8fed016a215cd5117aa6b443224bdf244f16aa6 Mon Sep 17 00:00:00 2001 From: Golddirio Date: Fri, 11 Jul 2025 17:49:15 +0800 Subject: [PATCH 1/2] Make beg_end math delimitor default --- .../markbind-plugin-begendMathDelimitor.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 packages/core/src/plugins/default/markbind-plugin-begendMathDelimitor.ts diff --git a/packages/core/src/plugins/default/markbind-plugin-begendMathDelimitor.ts b/packages/core/src/plugins/default/markbind-plugin-begendMathDelimitor.ts new file mode 100644 index 0000000000..b02ca0ea52 --- /dev/null +++ b/packages/core/src/plugins/default/markbind-plugin-begendMathDelimitor.ts @@ -0,0 +1,23 @@ +import katex from 'katex'; +import md from '../../lib/markdown-it'; + +const texmath = require('markdown-it-texmath'); + +let pluginAdded = false; + +function applyBegEndDelimiters() { + if (!pluginAdded) { + // Always use 'beg_end' delimiter regardless of site.json config + md.use(texmath, { + engine: katex, + delimiters: ['beg_end'], // force beg_end delimiter + }); + pluginAdded = true; + } +} + +export = { + beforeSiteGenerate: () => { + applyBegEndDelimiters(); + }, +}; From 9007072d58bd56eab540ef8b2938527aae94b1a6 Mon Sep 17 00:00:00 2001 From: Golddirio Date: Sat, 12 Jul 2025 08:37:38 +0800 Subject: [PATCH 2/2] Add the test for begend Math delimitor --- .../default/begendMathDelimitor.test.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 packages/core/test/unit/plugins/default/begendMathDelimitor.test.ts diff --git a/packages/core/test/unit/plugins/default/begendMathDelimitor.test.ts b/packages/core/test/unit/plugins/default/begendMathDelimitor.test.ts new file mode 100644 index 0000000000..b86a3d11f6 --- /dev/null +++ b/packages/core/test/unit/plugins/default/begendMathDelimitor.test.ts @@ -0,0 +1,29 @@ +import md from '../../../../src/lib/markdown-it/index'; +import begEndPlugin from '../../../../src/plugins/default/markbind-plugin-begendMathDelimitor'; + +describe('begEndPlugin', () => { + beforeEach(() => { + // Reset the plugin state if needed + jest.resetModules(); + }); + + it('should render \\begin{equation} math using beg_end delimiter', () => { + // apply the plugin + begEndPlugin.beforeSiteGenerate(); + + // input using the beg_end math delimiters + const input = ` +\\begin{equation} + a^2 + b^2 = c^2 +\\end{equation} +`; + + const output = md.render(input); + + // Check that the output contains KaTeX-rendered math HTML + expect(output).toContain(''); + expect(output).toContain('a^2'); + expect(output).toContain('b^2'); + expect(output).toContain('c^2'); + }); +});