Skip to content

Fix inline math rendering in markdown by using Text.rich instead of SingleChildScrollView#14

Open
frdteknikelektro wants to merge 1 commit into
foresightmobile:mainfrom
frdteknikelektro:main
Open

Fix inline math rendering in markdown by using Text.rich instead of SingleChildScrollView#14
frdteknikelektro wants to merge 1 commit into
foresightmobile:mainfrom
frdteknikelektro:main

Conversation

@frdteknikelektro
Copy link
Copy Markdown

Problem

Inline math expressions wrapped in SingleChildScrollView cause unwanted line breaks in markdown text. The opaque widget breaks flutter_markdown_plus's text merging chain, forcing each adjacent text segment into its own full-width RichText.

Solution

Differentiate rendering based on math style:

  • Display math (block): Keep SingleChildScrollView for horizontal scrolling of large expressions
  • Inline math: Use Text.rich with WidgetSpan so flutter_markdown_plus can merge it with adjacent text spans into a single RichText

Result: inline math now flows naturally with surrounding text without line breaks.

Changes

  • Split rendering logic into two paths based on MathStyle
  • Inline math returns Text.rich(TextSpan with WidgetSpan child)
  • Display math retains original SingleChildScrollView behavior
  • Added comments explaining the inline math approach

@frdteknikelektro frdteknikelektro marked this pull request as draft April 26, 2026 16:29
@frdteknikelektro frdteknikelektro marked this pull request as ready for review April 26, 2026 16:29
@frdteknikelektro
Copy link
Copy Markdown
Author

@gazreese Maybe you could take a look

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.

1 participant