🐛 fix(markdown): add remarkMath and remarkCjkFriendly to formatMarkdo…#124
Open
PoseidonLi0514 wants to merge 1 commit intolobehub:masterfrom
Open
🐛 fix(markdown): add remarkMath and remarkCjkFriendly to formatMarkdo…#124PoseidonLi0514 wants to merge 1 commit intolobehub:masterfrom
PoseidonLi0514 wants to merge 1 commit intolobehub:masterfrom
Conversation
…wn to prevent underscore escaping in math formulas
|
@PoseidonLi0514 is attempting to deploy a commit to the LobeHub OSS Team on Vercel. A member of the Team first needs to authorize it. |
Member
|
👍 @PoseidonLi0514 |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates markdown serialization to use the same remark plugin stack as parsing by adding remarkMath and remarkCjkFriendly to formatMarkdown, fixing incorrect escaping of underscores in LaTeX math formulas. Sequence diagram for updated markdown serialization with remark pluginssequenceDiagram
participant MarkdownDataSource
participant remarkProcessor as remark
participant remarkCjkFriendly
participant remarkMath
participant remarkGfm
MarkdownDataSource->>remarkProcessor: remark()
activate remarkProcessor
remarkProcessor->>remarkCjkFriendly: use(remarkCjkFriendly)
remarkProcessor->>remarkMath: use(remarkMath)
remarkProcessor->>remarkGfm: use(remarkGfm, singleTilde=false)
MarkdownDataSource->>remarkProcessor: processSync(markdown)
remarkProcessor->>remarkMath: handle_inline_and_block_math
remarkMath-->>remarkProcessor: preserve_math_syntax
remarkProcessor->>remarkGfm: apply_gfm_rules
remarkGfm-->>remarkProcessor: format_markdown
remarkProcessor-->>MarkdownDataSource: result.toString()
deactivate remarkProcessor
Class diagram for MarkdownDataSource formatMarkdown plugin usageclassDiagram
class DataSource {
}
class MarkdownDataSource {
-formatMarkdown(markdown: string) string
}
class remark {
+use(plugin: any) remark
+use(plugin: any, options: any) remark
+processSync(markdown: string) VFile
}
class remarkCjkFriendly {
}
class remarkMath {
}
class remarkGfm {
}
class VFile {
+toString() string
}
MarkdownDataSource --|> DataSource
MarkdownDataSource ..> remark : uses
remark ..> remarkCjkFriendly : plugin
remark ..> remarkMath : plugin
remark ..> remarkGfm : plugin
remark --> VFile : returns
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
💻 变更类型 | Change Type
🔀 变更说明 | Description of Change
Fixed the issue where underscores in LaTeX math formulas were being incorrectly escaped.
Problem:
When users input math formulas containing underscores (e.g.,
$a_n$) in the editor, the markdown content retrieved viagetDocument('markdown')would escape the underscore to$a\_n$, causing incorrect math rendering.Root Cause:
The
formatMarkdownmethod inmarkdown-data-source.tsonly used theremarkGfmplugin during markdown serialization, without loading theremarkMathplugin. This caused remark to fail to recognize the$...$math formula syntax, treating it as plain text and escaping the underscore_as a potential emphasis marker.Solution:
Added
remarkMathandremarkCjkFriendlyplugins to theformatMarkdownmethod, aligning with the parsing flow inparse.ts:Result:
$a_n$→ Output$a\_n$❌$a_n$→ Output$a_n$✅📝 补充信息 | Additional Information
remarkMathplugin handles both parsing and serialization of math formulas, correctly recognizing$...$and$$...$$syntax after being addedremarkCjkFriendlyto maintain full consistency withparse.ts🔗 Related Issues
Fixes lobehub/lobehub#12303