diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 80195b050..5782e230b 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -217,6 +217,7 @@ Mumtaz Hajjo Alrifai Thomas Graves Jakub Fidler Valerie Enfys +Julien Chol ******************** diff --git a/qt/aqt/reviewer.py b/qt/aqt/reviewer.py index 1a8682773..da4b37985 100644 --- a/qt/aqt/reviewer.py +++ b/qt/aqt/reviewer.py @@ -749,13 +749,25 @@ class Reviewer: def typeAnsAnswerFilter(self, buf: str) -> str: if not self.typeCorrect: return re.sub(self.typeAnsPat, "", buf) + m = re.search(self.typeAnsPat, buf) + type_pattern = m.group(1) if m else "" orig = buf origSize = len(buf) buf = buf.replace("
", "") hadHR = len(buf) != origSize - expected = self.typeCorrect - provided = self.typedAnswer + initial_expected = self.typeCorrect + initial_provided = self.typedAnswer + expected, provided = gui_hooks.reviewer_will_compare_answer( + (initial_expected, initial_provided), type_pattern + ) + output = self.mw.col.compare_answer(expected, provided, self._combining) + output = gui_hooks.reviewer_will_render_compared_answer( + output, + initial_expected, + initial_provided, + type_pattern, + ) # and update the type answer area def repl(match: Match) -> str: diff --git a/qt/tools/genhooks_gui.py b/qt/tools/genhooks_gui.py index d0136fa3d..1acfab1f9 100644 --- a/qt/tools/genhooks_gui.py +++ b/qt/tools/genhooks_gui.py @@ -100,6 +100,44 @@ hooks = [ legacy_hook="showQuestion", legacy_no_args=True, ), + Hook( + name="reviewer_will_compare_answer", + args=[ + "expected_provided_tuple: tuple[str, str]", + "type_pattern: str", + ], + return_type="tuple[str, str]", + doc="""Modify expected answer and provided answer before comparing + + expected_provided_tuple is a tuple composed of: + - expected answer + - provided answer + type_pattern is the detail of the type tag on the card + + Return a tuple composed of: + - modified expected answer + - modified provided answer + """, + ), + Hook( + name="reviewer_will_render_compared_answer", + args=[ + "output: str", + "initial_expected: str", + "initial_provided: str", + "type_pattern: str", + ], + return_type="str", + doc="""Modify the output of default compare answer feature + + output is the result of default compare answer function + initial_expected is the expected answer from the card + initial_provided is the answer provided during review + type_pattern is the detail of the type tag on the card + + Return a string comparing expected and provided answers + """, + ), Hook( name="reviewer_did_show_answer", args=["card: Card"], @@ -846,7 +884,7 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest) 'content' is a list of HTML strings added by add-ons which you can append your own components or elements to. To equip your components with logic and styling please see `webview_will_set_content` and `webview_did_receive_js_message`. - + Please note that Anki's main screen is due to undergo a significant refactor in the future and, as a result, add-ons subscribing to this hook will likely require changes to continue working. @@ -861,7 +899,7 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest) 'content' is a list of HTML strings added by add-ons which you can append your own components or elements to. To equip your components with logic and styling please see `webview_will_set_content` and `webview_did_receive_js_message`. - + Please note that Anki's main screen is due to undergo a significant refactor in the future and, as a result, add-ons subscribing to this hook will likely require changes to continue working. @@ -1161,7 +1199,7 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest) args=["editor: aqt.editor.Editor", "path_or_nid: str | anki.notes.NoteId"], doc="""Called when the image occlusion mask editor has completed loading an image. - + When adding new notes `path_or_nid` will be the path to the image file. When editing existing notes `path_or_nid` will be the note id.""", ), @@ -1250,7 +1288,7 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest) name="addon_manager_will_install_addon", args=["manager: aqt.addons.AddonManager", "module: str"], doc="""Called before installing or updating an addon. - + Can be used to release DB connections or open files that would prevent an update from succeeding.""", ), @@ -1258,7 +1296,7 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest) name="addon_manager_did_install_addon", args=["manager: aqt.addons.AddonManager", "module: str"], doc="""Called after installing or updating an addon. - + Can be used to restore DB connections or open files after an add-on has been updated.""", ),