Skip to content

feat(cherry-markdown): add IsSupportMath parameter#470

Merged
ArgoZhang merged 4 commits intomasterfrom
feat-cherrymarkdown
Jun 16, 2025
Merged

feat(cherry-markdown): add IsSupportMath parameter#470
ArgoZhang merged 4 commits intomasterfrom
feat-cherrymarkdown

Conversation

@j4587698
Copy link
Copy Markdown
Contributor

@j4587698 j4587698 commented Jun 16, 2025

Link issues

fixes #469

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Enable formula support in CherryMarkdown by introducing a UseKatex flag that loads KaTeX assets and configures the markdown engine, while upgrading to cherry-markdown.core.js and consolidating editor options.

New Features:

  • Add UseKatex parameter to enable math formula rendering via KaTeX in CherryMarkdown component
  • Lazy-load KaTeX JS and CSS assets when UseKatex is enabled

Enhancements:

  • Switch to using cherry-markdown.core.js and spread all options into the editor initialization
  • Remove individual option assignments in favor of spreading the options object

@bb-auto
Copy link
Copy Markdown

bb-auto Bot commented Jun 16, 2025

Thanks for your PR, @j4587698. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jun 16, 2025

Reviewer's Guide

Upgrades the CherryMarkdown component to leverage the new core build, streamline initialization with spread options, and optionally render mathematical formulas via KaTeX when the new UseKatex flag is enabled.

Sequence Diagram: Conditional KaTeX Resource Loading and Initialization

sequenceDiagram
    participant CM_JS as CherryMarkdown.razor.js
    participant Browser as Browser/DOM
    participant Cherry as Cherry Engine

    CM_JS->>CM_JS: Receives options (including useKatex)
    alt options.useKatex is true
        CM_JS->>Browser: addScript('./_content/BootstrapBlazor.CherryMarkdown/js/katex.min.js')
        activate Browser
        Browser-->>CM_JS: KaTeX JS loaded
        deactivate Browser
        CM_JS->>Browser: addLink('./_content/BootstrapBlazor.CherryMarkdown/css/katex.min.css')
        activate Browser
        Browser-->>CM_JS: KaTeX CSS loaded
        deactivate Browser
        CM_JS->>CM_JS: Configure options.engine for KaTeX
        CM_JS->>CM_JS: Configure options.externals for KaTeX (window.katex)
    end
    CM_JS->>Cherry: new Cherry({...options})
    activate Cherry
    Note right of Cherry: Initialized with relevant options
    deactivate Cherry
Loading

Class Diagram: Updates to CherryMarkdown Component Classes

classDiagram
    class CherryMarkdown {
        +bool UseKatex ## (New Parameter)
        #OnInitialized() ## (Modified to pass UseKatex to options)
    }
    class CherryMarkdownOption {
        +bool UseKatex ## (New Property)
    }
    CherryMarkdown ..> CherryMarkdownOption : uses/configures
Loading

File-Level Changes

Change Details Files
Refactored init to use CherryMarkdown core, dynamic KaTeX loading, and spread options in editor initialization
  • Replace minified import with core build
  • Import addScript and conditionally inject KaTeX CSS/JS when UseKatex is true
  • Configure markdown engine and externals for KaTeX rendering
  • Remove erroneous delete of options.useKatexuseKatex property
  • Collapse explicit value/editor/toolbars into a single spread of md._options
src/components/BootstrapBlazor.CherryMarkdown/Components/CherryMarkdown/CherryMarkdown.razor.js
src/components/BootstrapBlazor.CherryMarkdown/wwwroot/js/cherry-markdown.core.js
src/components/BootstrapBlazor.CherryMarkdown/wwwroot/js/cherry-markdown.min.js
Introduced UseKatex parameter to the component API
  • Add bool UseKatex parameter in CherryMarkdown.razor.cs and assign it to Option.UseKatex
  • Extend CherryMarkdownOption class to include UseKatex property
src/components/BootstrapBlazor.CherryMarkdown/Components/CherryMarkdown/CherryMarkdown.razor.cs
src/components/BootstrapBlazor.CherryMarkdown/Components/CherryMarkdown/CherryMarkdownOption.cs
Added KaTeX asset files for math formula support
  • Add katex.min.js and katex.min.css to the component’s wwwroot
  • Ensure these assets are loaded only when UseKatex is enabled
src/components/BootstrapBlazor.CherryMarkdown/wwwroot/js/katex.min.js
src/components/BootstrapBlazor.CherryMarkdown/wwwroot/css/katex.min.css

Assessment against linked issues

Issue Objective Addressed Explanation

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto Bot added the enhancement New feature or request label Jun 16, 2025
@bb-auto bb-auto Bot requested a review from ArgoZhang June 16, 2025 02:16
@bb-auto bb-auto Bot added this to the v9.2.0 milestone Jun 16, 2025
ArgoZhang and others added 3 commits June 16, 2025 10:52
Co-Authored-By: j4587698 <24642446+j4587698@users.noreply.github.com>
@ArgoZhang ArgoZhang changed the title 更新cherry-markdown版本,支持公式 feat(cherry-markdown): add IsSupportMath parameter Jun 16, 2025
@ArgoZhang ArgoZhang merged commit 6372a3b into master Jun 16, 2025
1 check passed
@ArgoZhang ArgoZhang deleted the feat-cherrymarkdown branch June 16, 2025 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(cherry-markdown): add IsSupportMath parameter

2 participants