-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add hooks for comparing answers #3855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
326c489 to
059df22
Compare
|
This looks interesting. Is it possible to update this PR to also support modifying the behaviour of the compare_answer feature using the card templates so that it would also work on mobile? |
|
@user1823 thanks for your comment. Could you please elaborate what you mean? When you talk about mobile, which client are you referring to? |
|
It looks like you are using an add-on to modify the answers compared by Anki. But add-ons don't work on mobile. So, is it possible to use JS in a card template to achieve the same?
Card templates should work on any client, whether it is Anki Desktop, AnkiMobile, AnkiWeb or AnkiDroid. |
|
You are correct, this PR will only work for addons. It is already possible to modify the output of The original need comes from an existing addon written in Python. So it would be possible to rewrite it in Javascript, but this is outside of the scope of this PR. That’s why I do not really understand how modifying the compared answer within a card template is related to this PR. Any additional pointer is welcome. |
Yeah, one can modify the If there is a way to allow JS to alter the
You are introducing a feature but users who review on mobile won't be able to use it. So, I am suggesting that we provide a way for mobile users to benefit from this too. But after reviewing the code, I now think that implementing it in that way will need a drastically different approach. So, that deserves another PR (by you or someone else). My request would probably be easier to implement after |
|
Thanks @user1823 for this detailed explanation. |
|
A JS-based solution is not practical at this time, but happy to add some Python hooks to avoid the need for monkey-patching. Changes look fine, but the CONTRIBUTORS file took a conflict - would you mind updating it again? |
059df22 to
60d652b
Compare
|
Thanks @dae. Conflict resolved. |
Following the suggestion made on the forum Hook for Collection.compare_answer and welcomed by @dae, this PR creates filter hooks associated with the compare answer feature.
The use case has been discussed in issue #40 of answerset add-on.
Two filter hooks would be created with different scopes:
reviewer_will_compare_answer(expected_provided_tuple: tuple[str, str]), updates expected and provided. This would enable simple modifications of the answers, while letting anki process the comparison. Examples use cases could be: reformatting the provided answer, shuffling the order of the expected answers...reviewer_will_render_compared_answer(output: str, expected_initial: str, provided_initial: str), enables an update or a complete rewrite of the defaultcompare_answer.While
answersetwill mainly usereviewer_will_render_compared_answer,reviewer_will_compare_answerwill enable more simple use cases.As these new hooks would enable add-ons to provide changes to the
compare_answerfeature across all cards, I feel that this could also let the add-ons enabled only for specific cards, for example by having type patterns liketype:UseMyAddonFieldNameortype:MyAddon:FieldName. The former would just require users to rename their fields, while the latter is not possible right now becauseMyAddonwould be filtered out.As this may be a less critical feature, I added
type_patternto the hooks as an "optional" commit.