thunder-app / thunder

Thunder - An open-source cross-platform Lemmy client for iOS and Android built with Flutter
https://thunderapp.dev
GNU Affero General Public License v3.0
781 stars 66 forks source link

Additional line breaks before subscript text #1196

Open sukhmel opened 5 months ago

sukhmel commented 5 months ago

Bug Description

When subscript text is inputted with ~text~ after long enough text without breaks, a post renders with a line break before that text

Thunder rendering post with subscript text

Expected Behaviour

There should be no extra line break

lemmy-ui renders post with a subscript, as seen on programming.dev

Steps to Reproduce

Post a text like . .~s~, you may need to adjust amount of spaces

Additional Context

It seems to depend on screen size and interface size settings:

  1. if the text fits into one line, the subscript part is placed correctly
  2. as preceding line grows and rendered text length grows, the subscript is moved to the next line*
  3. if the preceding line length grows further, additional line breaks will be added to fit line into post window, but an extra line breaks before subscript will remain
  4. Extra line break depends on visible text size, not on a character count, so I suppose that's a rendering bug rather than some markdown engine bug. But I know nothing of Thunder internals, so this might as well be nonsensical statement 😅

    * I would argue that it should take the preceding text to the next line if there is no space before subscipt, i.e. not put line break between text~index~ but allow to break text ~index. That's a bit tangential to the issue, though.

App Version

0.3.0-1

Device

Pixel 8 Pro

OS

Android 14 kernel 5.15.110-android14-11-gcc48824eebe8-ab10865596

hjiangsu commented 5 months ago

Thanks for the detailed report! Markdown itself doesn't officially support subscript or superscript tags (see https://github.com/flutter/flutter/issues/81717) so this had to be implemented manually 😅

hjiangsu commented 5 months ago

Just a quick update - I tried a couple of changes on my end to see if I could fix this issue easily, and it seems like its going to take some effort to get this to work properly.

This is what I believe is happening at the moment:

I tried to parse both the preceding text and super/subscript text together to get past that issue with it breaking into the next line, but this completely breaks markdown formatting for the preceding text (e.g., bolded text gets shown as raw markdown). This also causes another similar issue with line breaking if there are multiple super/subscripts in a single paragraph.