fix(card-browser): render code blocks in error messages#21003
fix(card-browser): render code blocks in error messages#21003DebugWithAryan wants to merge 3 commits intoankidroid:mainfrom
Conversation
Errors from the Anki backend can wrap content in <pre>...</pre> for monospace presentation (e.g. regex parse errors). AnkiDroid's plain TextView showed the literal tags. Strip them and apply a monospace TypefaceSpan + a theme-aware BackgroundColorSpan so the content reads as a code block. Closes ankidroid#21001
|
First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible. |
|
The grey bar is an Emulator bug according to David, but what about the background color of the "code" text? I'm not a fan. |
|
Yes, I have removed that text highlighted background @ZornHadNoChoice |
Errors from the Anki backend can wrap content in <pre>...</pre> for monospace presentation (e.g. regex parse errors). AnkiDroid's plain TextView showed the literal tags. Strip them and apply a monospace TypefaceSpan so the content reads as a code block. Closes ankidroid#21001
|
@ZornHadNoChoice guide me if any changes required |
|
Visually, it looks fine (aside from the emulator bug). You have to wait for the devs to comment on the code. |
Ok thank you |
|
Can you confirm you didn't use an LLM to write this? (I can see LLM usage in description) We want new contributors to gain hands-on experience with our code. While LLMs are efficient, using them for beginner-level issues takes away the chance for developers to learn by doing. https://github.com/ankidroid/Anki-Android/blob/main/AI_POLICY.md#new-contributors |
No I haven't used LLM for description I just checked other PR's for description idea as I'm new to this. |
david-allison
left a comment
There was a problem hiding this comment.
We should match Anki Desktop here and let them fix the output.
Only handle backticks for now, as that's known to be handled upstream
https://forums.ankiweb.net/t/bug-regex-parse-error-dialog/69660
Purpose / Description
When a card-browser search produces an error wrapped in
<pre>...</pre>by the Anki backend (e.g.
re:b[triggers a regex parse error), theerror dialog displayed the literal
<pre>and</pre>tags insteadof rendering the code block. Anki Desktop renders these via Qt's HTML
support; AnkiDroid uses a plain
TextView, so the markup leakedthrough.
Fixes
Approach
formatErrorMessage(message, codeBackgroundColor)incom.ichi2.utilsthat strips<pre>tags and appliesTypefaceSpan("monospace")+BackgroundColorSpanto the innercontent.
Context.formatErrorMessage(message)extension that resolvesthe code-block background from
?attr/colorSurfaceContainerHighestvia the existing
Themes.getColorFromAttrhelper, so it adapts tolight/dark themes.
Context.showErrorso every error dialog benefits.<pre>block is preserved so caret indicators(e.g.
^under the offending character of a regex) stay aligned.How Has This Been Tested?
ErrorMessageFormatterTest:<pre>regex parse error: …</pre>becomes plain text with aTypefaceSpan("monospace")over the code rangere:b[andandin the card browseron a debug build.
Checklist