Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ Mumtaz Hajjo Alrifai <[email protected]>
Thomas Graves <[email protected]>
Jakub Fidler <[email protected]>
Valerie Enfys <[email protected]>
Julien Chol <https://github.com/chel-ou>

********************

Expand Down
16 changes: 14 additions & 2 deletions qt/aqt/reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,13 +749,25 @@ def typeAnsQuestionFilter(self, buf: str) -> str:
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("<hr id=answer>", "")
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:
Expand Down
48 changes: 43 additions & 5 deletions qt/tools/genhooks_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,44 @@ def custom_link_handler(url):
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"],
Expand Down Expand Up @@ -846,7 +884,7 @@ def on_top_toolbar_did_init_links(links, toolbar):
'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.
Expand All @@ -861,7 +899,7 @@ def on_top_toolbar_did_init_links(links, toolbar):
'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.
Expand Down Expand Up @@ -1161,7 +1199,7 @@ def might_reject_empty_tag(optional_problems, note):
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.""",
),
Expand Down Expand Up @@ -1250,15 +1288,15 @@ def might_reject_empty_tag(optional_problems, note):
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.""",
),
Hook(
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.""",
),
Expand Down