anki icon indicating copy to clipboard operation
anki copied to clipboard

fix: prevent <br> from appearing as text in error message

Open leedoughty opened this issue 1 month ago • 2 comments

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: before

After: after

leedoughty avatar Nov 26 '25 17:11 leedoughty

This change was proposed before, but rejected: https://github.com/ankitects/anki/pull/4246#issuecomment-3158136028

iamllama avatar Nov 27 '25 01:11 iamllama

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.

abdnh avatar Dec 01 '25 19:12 abdnh

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.

leedoughty avatar Dec 02 '25 18:12 leedoughty