fix: prevent <br> from appearing as text in error message
Fixes: https://github.com/ankitects/anki/issues/4448
An issue was found where a <br> tag appeared as literal text in an error message when editing the card template. After investigating, I discovered that the error text was being set as PlainText. Changing this to RichText allows the HTML <br> tag to render as an actual line break, so the error message now displays as intended.
Before:
After:
This change was proposed before, but rejected: https://github.com/ankitects/anki/pull/4246#issuecomment-3158136028
Maybe we can get away with adding a special case for CardTypeError: Check the type of the exception in show_exception() and pass a text format to _init_message_box() accordingly.
Maybe we can get away with adding a special case for CardTypeError: Check the type of the exception in show_exception() and pass a text format to _init_message_box() accordingly.
Thanks for the suggestion, @abdnh. I’ve updated the code so that show_exception() now checks for CardTypeError and passes the RichText text format to _init_message_box() just for that case. I tested it out and confirmed that HTML in CardTypeError messages now displays correctly, while other errors still use plain text. Let me know if you have any other thoughts or suggestions.