Skip to content

Conversation

@Golddirio
Copy link

@Golddirio Golddirio commented Jul 12, 2025

What is the purpose of this pull request?

  • Documentation update
  • Bug fix
  • Feature addition or enhancement
  • Code maintenance
  • DevOps
  • Improve developer experience
  • Others, please explain:

Closes #2710

Overview of changes:
The beg_end Math delimitor is made default without the need to configure in site.json for users. Hence, the following code is no longer needed if the user would like to use beg_end:

 {
  "plugins": [
    "mathDelimiters"
  ],
  "pluginsContext" : {
    "mathDelimiters" : {
      "delimiters": ["beg_end"]
    }
  },
}

Anything you'd like to highlight/discuss:
This improvement does not affect the use of other Math delimitors. If the user would like to use other delimitors other than beg_end they still need to configure in site.json as usual.

Testing instructions:

Proposed commit message: (wrap lines at 72 characters)
Make beg_end math delimitor default


Checklist: ☑️

  • Updated the documentation for feature additions and enhancements
  • Added tests for bug fixes or features
  • Linked all related issues
  • No unrelated changes

Reviewer checklist:

Indicate the SEMVER impact of the PR:

  • Major (when you make incompatible API changes)
  • Minor (when you add functionality in a backward compatible manner)
  • Patch (when you make backward compatible bug fixes)

At the end of the review, please label the PR with the appropriate label: r.Major, r.Minor, r.Patch.

Breaking change release note preparation (if applicable):

  • To be included in the release note for any feature that is made obsolete/breaking

Give a brief explanation note about:

  • what was the old feature that was made obsolete
  • any replacement feature (if any), and
  • how the author should modify his website to migrate from the old feature to the replacement feature (if possible).

@Golddirio Golddirio marked this pull request as ready for review July 12, 2025 00:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR makes the beg_end math delimiter available by default without requiring explicit configuration in site.json. The change simplifies the user experience by automatically enabling support for LaTeX \begin{equation}...\end{equation} syntax.

  • Introduces a new default plugin that automatically applies the beg_end math delimiter
  • Removes the need for users to manually configure mathDelimiters plugin for basic equation support
  • Maintains backward compatibility with existing delimiter configurations

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/core/src/plugins/default/markbind-plugin-begendMathDelimitor.ts New plugin that automatically applies beg_end delimiter using markdown-it-texmath
packages/core/test/unit/plugins/default/begendMathDelimitor.test.ts Test coverage for the new default plugin functionality
Comments suppressed due to low confidence (1)

packages/core/test/unit/plugins/default/begendMathDelimitor.test.ts:7

  • The jest.resetModules() call may not effectively reset the pluginAdded flag since it's a module-level variable. Consider testing the plugin's idempotent behavior more explicitly.
    jest.resetModules();

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.
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.
@codecov
Copy link

codecov bot commented Aug 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.92%. Comparing base (f681976) to head (9007072).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2737      +/-   ##
==========================================
+ Coverage   52.84%   52.92%   +0.07%     
==========================================
  Files         130      131       +1     
  Lines        7162     7173      +11     
  Branches     1591     1502      -89     
==========================================
+ Hits         3785     3796      +11     
  Misses       3072     3072              
  Partials      305      305              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@gerteck gerteck left a comment

Choose a reason for hiding this comment

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

Thanks @Golddirio for your PR!

The goal of enabling beg_end delimiters by default makes sense, but the approach here feels heavier than necessary.

MarkBind’s markdown pipeline already initializes markdown-it with its math delimiters in a single, central location. Instead of introducing a new plugin (with its own state, lifecycle hook, and tests), it might be worth looking at where the default delimiter list is set during markdown-it setup. That’s the same place our other delimiters (dollar, brackets) are configured.

By adjusting that initialization directly, we could achieve the same effect without adding an extra plugin layer or lifecycle dependency. This would also keep delimiter logic in one place, consistent with the architecture described here.

See: MarkBind Architecture
See: supported delimiters

Edit: Additionally, consider updating the docs as well to reflect any new changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import beg_end markdown-it-texmath delimiters by default

2 participants