Proof of concept for issue #416 - adds Markdown rendering in TUI #417
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here's a PR against master that uses html2text to render statuses in Markdown. (per issue #416) It does this all the time for console output (
toot timeline
etc.) and copy-to-clipboard. In the TUI, it renders Markdown as a fallback if theurwidgets
library is unavailable.It works OK, but has some rendering challenges due to quirks and limitations of html2text. I think I'll try substituting
markdown-it-py to see if it does a better job.Turns out, markdown-it-py goes the opposite direction, from markdown to HTML.I tested markdownify instead; it's less flexible than html2text and has its own quirks, so it's a question of which library's quirks we can put up with. Or find another. The only other solution I've found is pandoc, which relies on a Haskell library. So that's not ideal.
For the moment, I'm sticking with html2text.
Another issue is that urwid Text widgets wrap text as needed, and html2text depends on fixed width lines in order to render things like blockquotes and lists correctly. If the TUI status window is too narrow, blockquotes and lists won't look right. Not much we can do about this other than detect the status window width and re-render the Markdown on any window resize 🤮 . Or ignore the problem (my preferred solution.) You can see an example of this line wrapping problem in the image below: