style: add Math Preprocessing for Markdown Component #335
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Math Preprocessing for Markdown Component
Summary
This PR introduces preprocessing for math expressions within the Markdown component. The component now transforms inline math (e.g.,
\(...\)
) to use the$ ... $
format and block math (e.g.,\[...\]
) to use the$$ ... $$
format. This enhancement helps in standardizing the math syntax before it’s processed by the Markdown renderer.Changes
useMemo
hook in theMarkdown
function to preprocess thechildren
content.\(...\)
with$ ... $
.\[...\]
with\n$$\n ... \n$$\n
, ensuring that block math expressions are placed on separate lines.MarkdownContent
component, preserving all existing functionalities like code highlighting, link rendering, and file block handling.Rationale
Previously, the Markdown component did not handle the conversion of LaTeX-style math delimiters wrapped in
\(...\)
and\[...\]
, which could lead to inconsistent rendering of math expressions. By preprocessing the content, we ensure a more robust and flexible handling of both inline and block math expressions.Possible Drawbacks
\(...\)
and\[...\]
delimiters universally. This means that any non-mathematical content using these delimiters for other purposes might be unintentionally transformed, potentially leading to unexpected formatting issues.How to Test
This is inline math: \(a^2 + b^2 = c^2\)
This is inline math: $ a^2 + b^2 = c^2 $
Here is block math: \[ \int_0^\infty e^{-x} dx \]
Here is block math: $$ \int_0^\infty e^{-x} dx $$
Additional Notes
acceptHtml
prop.Label
,Link
,Code
), ensuring that the overall markdown styling and functionalities remain consistent.