Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import katex from 'katex';
import md from '../../lib/markdown-it';

const texmath = require('markdown-it-texmath');
Copy link

Copilot AI Aug 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ES6 import syntax instead of require() to maintain consistency with the other imports in the file.

Suggested change
const texmath = require('markdown-it-texmath');
import * as texmath from 'markdown-it-texmath';

Copilot uses AI. Check for mistakes.

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();
},
};
Copy link

Copilot AI Aug 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The global pluginAdded flag could cause issues in multi-threaded environments or when the module is imported multiple times. Consider using a more robust state management approach.

Suggested change
};
const plugin = {
pluginAdded: false,
applyBegEndDelimiters() {
if (!this.pluginAdded) {
// Always use 'beg_end' delimiter regardless of site.json config
md.use(texmath, {
engine: katex,
delimiters: ['beg_end'], // force beg_end delimiter
});
this.pluginAdded = true;
}
},
beforeSiteGenerate() {
this.applyBegEndDelimiters();
},
};
export = plugin;

Copilot uses AI. Check for mistakes.
Original file line number Diff line number Diff line change
@@ -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('<span class="katex-display">');
expect(output).toContain('a^2');
expect(output).toContain('b^2');
expect(output).toContain('c^2');
});
});
Loading