mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-25 09:16:02 +03:00
[GH-ISSUE #1885] Add a Format Check rule to convert $$E=mc^2$$ into multi‑line display math for Typora compatibility #2617
Labels
No labels
bug
enhancement
enhancement
enhancement
fixed in next
fixed in next
fixed in next
new rule
new rule
new rule
pull-request
question
refactoring
refactoring
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/markdownlint#2617
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sleepyy-dog on GitHub (Dec 7, 2025).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/1885
In many AI answers, the format for the display equations is as follows:
And it can be successfully rendered on AI web pages. However, in Typora, the above would only be rendered as an inline equation.
I hope to add a rule to the 'Format Check' plugin's rule document that can fix:
to
This way, the requirement for successfully rendering display equations can be achieved. Due to my limited expertise, I am not familiar with the rule document. I hope someone more experienced can add this rule to the rule document.Hope i can use this new hunction in plugin.
@obgnail commented on GitHub (Dec 7, 2025):
How to distinguish inline
$$vs$for a custom rule?Hi, @DavidAnson
I am trying to implement a custom rule to enforce single-dollar delimiters (
$) for inline math, as AI-generated content often incorrectly uses double-dollars ($$) for inline equations.I am facing two technical hurdles:
markdownlinthas moved away frommarkdown-it. Testing withmicromarkreveals that$math$and$$math$$produce identical output, making them indistinguishable in the result.Reproduction of the parser issue:
While
markdown-itclearly differentiates them:My Question: Is there a way within the current
markdownlintarchitecture to access similar metadata (specifically the rawmarkupor a distinct token type) for math nodes? I need to validate the delimiter used in the source code without relying on Regex, which causes false positives in code blocks.Thanks.
@DavidAnson commented on GitHub (Dec 7, 2025):
If you register the custom rule as using the micromark parser, you can examine the token stream for your scenario. I find it easiest to create a very small Markdown file and then look through the tokens to see how it presents. In this case, you will be looking for tokens with names like those enumerated at the bottom of this file: https://github.com/micromark/micromark-extension-math/blob/main/dev/index.d.ts
In this case, I think you just need to look for the start/stop markers for inline math content and provide a single fix action that replaces the entire math block with itself plus newline characters.
Actually, I guess the two of you are asking slightly different questions. At any rate, the approach you both take should be similar and along the lines of what I outlined above.
I hope this helps – good luck!
@DavidAnson commented on GitHub (Dec 7, 2025):
FYI if you hadn't seen this: https://github.com/DavidAnson/markdownlint/blob/main/doc/CustomRules.md
@obgnail commented on GitHub (Dec 7, 2025):
@DavidAnson
Thanks for the support! I managed to implement the rule.
I discovered that inspecting the
mathTextSequencetoken withinmathTextis the key. By simply checking ifmathTextSequence.text.length > 1, I can reliably detect and handle cases like$$directly.Appreciate the help! 🙌
Click to view my code
@sleepyy-dog commented on GitHub (Dec 8, 2025):
thanks to @DavidAnson @obgnail ,i solve my probelm with the following rule code,thanks your helps!
click here to view code
@tichaonacherai-sudo commented on GitHub (Dec 23, 2025):
Very well done