Skip to content

fix: promote display math blocks from mixed paragraphs#179

Merged
hryhoriiK97 merged 3 commits intomainfrom
fix/promote-display-math-from-mixed-paragraphs
Mar 26, 2026
Merged

fix: promote display math blocks from mixed paragraphs#179
hryhoriiK97 merged 3 commits intomainfrom
fix/promote-display-math-from-mixed-paragraphs

Conversation

@hryhoriiK97
Copy link
Copy Markdown
Collaborator

What/Why?

Display math ($$...$$) on a line directly after text (no blank line) was rendered as plain text. md4c merges such content into a single Paragraph, and the existing unwrap logic only handled the pure case (all children are display math). Extended it to also split mixed paragraphs — keeping the leading text in place and promoting trailing display math blocks to top-level siblings.

Testing

export const sampleMarkdown = `
Based on the image provided, we can solve the quadratic equation as follows:

### 1. Identify the coefficients
For a quadratic equation in the form $ax^2 + bx + c = 0$, we have:
- $a = 1$
- $b = -3$
- $c = 2$

### 2. The Quadratic Formula
We use the standard formula for finding the roots:
$$x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$$

### 3. Substitution & Calculation
Substitute the values into the formula:
$$x = \\frac{-(-3) \\pm \\sqrt{(-3)^2 - 4(1)(2)}}{2(1)}$$
$$x = \\frac{3 \\pm \\sqrt{9 - 8}}{2}$$
$$x = \\frac{3 \\pm \\sqrt{1}}{2}$$

### 4. Final Results
Simplified, we get two possible values for $x$:
- $x_1 = \\frac{3 + 1}{2} = 2$
- $x_2 = \\frac{3 - 1}{2} = 1$

**Solution set: $\\{1, 2\\}$**
`;

Screenshots

iOS Android

PR Checklist

  • Code compiles and runs on iOS
  • Code compiles and runs on Android
  • Updated documentation/README if applicable
  • Ran example app to verify changes

@hryhoriiK97 hryhoriiK97 changed the title Fix/promote display math from mixed paragraphs fix: promote display math blocks from mixed paragraphs Mar 26, 2026
@hryhoriiK97 hryhoriiK97 merged commit 1003e02 into main Mar 26, 2026
5 checks passed
@hryhoriiK97 hryhoriiK97 deleted the fix/promote-display-math-from-mixed-paragraphs branch March 26, 2026 12:04
@ppaanngggg
Copy link
Copy Markdown

Amazing! Thank you so much for that fix. Will it be fixed in the next release?

@hryhoriiK97
Copy link
Copy Markdown
Collaborator Author

Amazing! Thank you so much for that fix. Will it be fixed in the next release?

Yes, it will be included in version 0.5.0. In the meantime, you can test this using the react-native-enriched-markdown@nightly release.

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.

2 participants