ankitects / ankitects/anki

_flipQA regex rejects quoted <hr id="answer"> attribute, causing confusing warning

Open Beginner friendly
#4,785 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
31.2k
Forks
3.2k
Avg merge
2d 8h
Merged PRs (30d)
72

Description

## Summary

The `_flipQA` method in `qt/aqt/clayout.py` uses a regex that only recognises the unquoted HTML form `


`. The equally valid — and far more common — quoted forms `
` and `
` do not match, so clicking the **Flip Q↔A** button in the card template editor silently fails and displays:

> *Anki couldn't find the line between the question and answer. Please adjust the template manually to switch the question and answer.*

This is confusing because the template is perfectly valid; the attribute is simply quoted, as any modern HTML editor or linter would produce.

## Affected code

**File:** `qt/aqt/clayout.py`

```python
def _flipQA(self, src: dict, dst: dict) -> None:
m = re.match("(?s)(.+)


(.+)", src["afmt"])
if not m:
showInfo(tr.card_templates_anki_couldnt_find_the_line_between())
return
self.change_tracker.mark_basic()
dst["afmt"] = "{{FrontSide}}\n\n
\n\n%s" % src["qfmt"]
dst["qfmt"] = m.group(2).strip()
```

The regex on line 2 requires the exact literal string `


`. It will not match any of these equally valid HTML spellings:

| Template text | Matches? |
|---|---|
| `


` | ✅ |
| `
` | ❌ |
| `
` | ❌ |
| `
` | ❌ |
| `
` | ❌ |

## Steps to reproduce

1. Create a new note type (or edit an existing one).
2. In the back template, write the separator as `


` (with quotes — the default produced by most HTML editors).
3. Open the card template editor and click **Flip Q↔A**.
4. Observe the warning: *"Anki couldn't find the line between the question and answer…"* — even though the template is valid.

Contributor guide

Open the contributing guide

Research direction

Start in qt/aqt/clayout.py at _flipQA and reproduce the failure with the quoted separator forms listed in the issue. Verify that Flip Q↔A accepts quoted and self-closing


variants, preserves the existing behavior for the unquoted form, and no longer shows the warning for valid templates.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, python
Domain
desktop
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.