mastodon-android icon indicating copy to clipboard operation
mastodon-android copied to clipboard

Render Markdown lists correctly

Open sk22 opened this issue 3 years ago • 9 comments

Closes mastodon#152

sk22 avatar Nov 29 '22 23:11 sk22

(ignore the bold thing that's actually meant to be rendered in italic – but not in this pull request) Screenshot_2022-11-30-00-09-56-790-edit_org joinmastodon android Screenshot_2022-11-30-00-09-46-304-edit_org joinmastodon android

sk22 avatar Nov 29 '22 23:11 sk22

Hm. But Markdown isn't an officially supported Mastodon feature 🤔

grishka avatar Nov 29 '22 23:11 grishka

well, people come across posts using "advanced" html tags, including lists, all the time.

mastodon for web renders this

LIST HEADER

* item 1
* item 2

LIST FOOTER
<p>LIST HEADER<p>
<ul>
  <li>item 1</li>
  <li>item 2</li>
</ul>
<p>LIST FOOTER</p>

like this:

image

…which is still readable.

mastodon for android renders it like this:

Screenshot_2022-11-30-00-15-57-061-edit_org joinmastodon android sk

sk22 avatar Nov 29 '22 23:11 sk22

my pull request can be easily adapted to archive what you see on mastodon web; by

  • removing the "head" switch-case for "p" (which ensures the empty line after lists/non-paragraphs)
  • removing the "head" switch-case for "li"
  • moving the "tail" case for "li" outside the !openSpans.isEmpty() block

edit: i've simplified the implementation since

sk22 avatar Nov 29 '22 23:11 sk22

Screenshot_2022-11-30-00-24-58-052-edit_org joinmastodon android sk debug

would look like this. you can add commits to this PR if you want to

sk22 avatar Nov 29 '22 23:11 sk22

found an issue with my implementation: list items will always append a line break, even if there's nothing after them – resulting in an empty line at the end of the SpannableStringBuilder

sk22 avatar Nov 30 '22 00:11 sk22

okay, fixed it – also, the implementation feels much cleaner now

sk22 avatar Nov 30 '22 09:11 sk22

… and since #152 also applies to other block elements, like <blockquote>, it's probably smart to insert spaces (just like after <p> elements), so i changed the logic a bit.

sk22 avatar Nov 30 '22 10:11 sk22

Hm. But Markdown isn't an officially supported Mastodon feature 🤔

it is now: https://github.com/mastodon/mastodon/pull/23913

sk22 avatar Mar 06 '23 16:03 sk22

I'm closing this because I since added support for displaying all text formatting that the web app supports.

grishka avatar Mar 18 '25 16:03 grishka