mirror of
https://github.com/ankitects/anki.git
synced 2026-07-28 13:49:05 -04:00
## Summary - add a generated `docs-site/` Mintlify proof of concept for a unified Anki docs site - migrate the desktop manual, AnkiMobile docs, FAQs, add-on docs, translation docs, release notes, legacy docs, and repo-local Sphinx/MyST developer docs into the POC tree - add a migration helper that preserves mdBook ordering, handles common MDX incompatibilities, and regenerates the landing-page-inspired Mintlify styling - apply minimal styling based on the current Anki landing page: Anki logo, Hanken Grotesk, blue primary color, subtle surfaces, and compact nav treatment ## Validation - `uv run --with ty ty check tools/mintlify_poc_migrate.py` - `source ~/.nvm/nvm.sh && nvm use 22.15.0 && mint validate` - previewed locally with `mint dev --port 3000` and checked the home page/developer docs in browser ## Notes This is intentionally a draft POC. It does not remove the existing Sphinx or mdBook docs flows yet; it demonstrates what bringing the sources into this repo and building from a single Mintlify root could look like. --------- Co-authored-by: Andrew Sanchez <andrewsanchez@users.noreply.github.com> Co-authored-by: Luc Mcgrady <lucmcgrady@gmail.com> Co-authored-by: Abdo <abdo@abdnh.net>
61 lines
1.9 KiB
Plaintext
61 lines
1.9 KiB
Plaintext
---
|
|
title: "Reviewer Javascript"
|
|
---
|
|
|
|
For a general solution not specific to card review, see
|
|
[the webview section](./hooks-and-filters#webview).
|
|
|
|
Anki provides a hook to modify the question and answer HTML before it is
|
|
displayed in the review screen, preview dialog, and card layout screen.
|
|
This can be useful for adding Javascript to the card. If you wish to load external resources in your card, please see [managing external resources in webviews](./hooks-and-filters#managing-external-resources-in-webviews).
|
|
|
|
An example:
|
|
|
|
```python
|
|
from aqt import gui_hooks
|
|
def prepare(html, card, context):
|
|
return html + """
|
|
<script>
|
|
document.body.style.background = "blue";
|
|
</script>"""
|
|
gui_hooks.card_will_show.append(prepare)
|
|
```
|
|
|
|
The hook takes three arguments: the HTML of the question or answer, the
|
|
current card object (so you can limit your add-on to specific note types
|
|
for example), and a string representing the context the hook is running
|
|
in.
|
|
|
|
Make sure you return the modified HTML.
|
|
|
|
Context is one of: "reviewQuestion", "reviewAnswer", "clayoutQuestion",
|
|
"clayoutAnswer", "previewQuestion" or "previewAnswer".
|
|
|
|
The answer preview in the card layout screen, and the previewer set to
|
|
"show both sides" will only use the "Answer" context. This means
|
|
Javascript you append on the back side of the card should not depend on
|
|
Javascript that is only added on the front.
|
|
|
|
Because Anki fades the previous text out before revealing the new text,
|
|
Javascript hooks are required to perform actions like scrolling at the
|
|
correct time. You can use them like so:
|
|
|
|
```python
|
|
from aqt import gui_hooks
|
|
def prepare(html, card, context):
|
|
return html + """
|
|
<script>
|
|
onUpdateHook.push(function () {
|
|
window.scrollTo(0, 2000);
|
|
})
|
|
</script>"""
|
|
gui_hooks.card_will_show.append(prepare)
|
|
```
|
|
|
|
- onUpdateHook fires after the new card has been placed in the DOM,
|
|
but before it is shown.
|
|
|
|
- onShownHook fires after the card has faded in.
|
|
|
|
The hooks are reset each time the question or answer is shown.
|