Skip to content
Open
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
34 changes: 34 additions & 0 deletions docs/docs/en/flashcards/q-and-a-cards.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,37 @@ To include blank lines, see the section below.

These two cards are considered sibling cards. See [sibling cards](flashcards-overview.md#sibling-cards) regarding the
[Bury sibling cards until the next day](../user-options.md#flashcard-review) scheduling option.

---

## Multiple Choice Questions

You can create interactive Multiple Choice Questions (MCQ) by combining the Multi-line format with standard Markdown checklists.
Simply add a checklist on the front side of the card, marking the correct answer(s) with `[x]`.

```markdown
What is the capital of France?
- [ ] London
- [x] Paris
- [ ] Berlin
?
Paris is the capital of France.
```

!!! note "Displayed when reviewed"

<div class="grid" markdown>

!!! tip "Card Front"

What is the capital of France?<br/><br/>
🔘 London<br/>
🔘 Paris<br/>
🔘 Berlin<br/>

!!! tip "Card Back"

The correct option (`Paris`) is highlighted in green. If you selected a wrong option, it will be highlighted in red.<br/><br/>
Paris is the capital of France.

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,41 @@
& .sr-content .cloze-input {
height: 1.4rem;
}

& .sr-content .sr-mcq-option {
cursor: pointer;
padding: 8px 12px;
margin: 6px 0;
border: 1px solid var(--background-modifier-border);
border-radius: 6px;
background-color: var(--background-primary-alt);
transition: all 0.2s;
list-style: none;
text-decoration: none !important;
color: var(--text-normal) !important;
}

& .sr-content .sr-mcq-option:hover {
background-color: var(--background-modifier-hover);
border-color: var(--interactive-accent);
}

& .sr-content .sr-mcq-selected {
background-color: var(--background-modifier-active);
border-color: var(--interactive-accent);
}

& .sr-content .sr-mcq-correct {
background-color: var(--text-success, var(--color-green, #4caf50));
color: white !important;
border-color: var(--text-success, var(--color-green, #4caf50));
}

& .sr-content .sr-mcq-wrong {
background-color: var(--text-error, var(--color-red, #f44336));
color: white !important;
border-color: var(--text-error, var(--color-red, #f44336));
}
}

@media only screen and (orientation: landscape) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class CardContainer {

private clozeInputs: NodeListOf<HTMLInputElement> | null = null;
private clozeAnswers: NodeListOf<Element> | null = null;
private selectedMcqIndex: number | null = null;

private processReviewHandler: (response: ReviewResponse) => Promise<void>;
private skipCardHandler: () => void;
Expand Down Expand Up @@ -163,6 +164,7 @@ export class CardContainer {
}

public async drawCardFront(sessionData: SessionData, settings: SRSettings) {
this.selectedMcqIndex = null;
this.toolbar.setResetButtonDisabled(true);
// Update current deck info
this.cardState = sessionData.cardData.currentCardState;
Expand Down Expand Up @@ -221,6 +223,35 @@ export class CardContainer {
);
// Set scroll position back to top
this.content.scrollTop = 0;

// Process MCQ (Multiple Choice Questions) checkboxes
const listItems = this.content.findAll("li.task-list-item");
listItems.forEach((li, index) => {
li.addClass("sr-mcq-option");

const checkbox = li.querySelector("input[type='checkbox']") as HTMLInputElement | null;
if (checkbox) {
checkbox.style.display = "none";

if (this.cardState === CardState.Back) {
if (checkbox.checked) {
li.addClass("sr-mcq-correct");
} else if (this.selectedMcqIndex === index) {
li.addClass("sr-mcq-wrong");
}
}
}

if (this.cardState === CardState.Front) {
li.addEventListener("click", (e: Event) => {
e.preventDefault();
e.stopPropagation();
this.selectedMcqIndex = index;
li.addClass("sr-mcq-selected");
this.showAnswerHandler();
});
}
});
}

public drawPendingState(nextPendingDueUnix: number): void {
Expand Down
30 changes: 30 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,36 @@
& .sr-content .cloze-input {
height: 1.4rem;
}
& .sr-content .sr-mcq-option {
cursor: pointer;
padding: 8px 12px;
margin: 6px 0;
border: 1px solid var(--background-modifier-border);
border-radius: 6px;
background-color: var(--background-primary-alt);
transition: all 0.2s;
list-style: none;
text-decoration: none !important;
color: var(--text-normal) !important;
}
& .sr-content .sr-mcq-option:hover {
background-color: var(--background-modifier-hover);
border-color: var(--interactive-accent);
}
& .sr-content .sr-mcq-selected {
background-color: var(--background-modifier-active);
border-color: var(--interactive-accent);
}
& .sr-content .sr-mcq-correct {
background-color: var(--text-success, var(--color-green, #4caf50));
color: white !important;
border-color: var(--text-success, var(--color-green, #4caf50));
}
& .sr-content .sr-mcq-wrong {
background-color: var(--text-error, var(--color-red, #f44336));
color: white !important;
border-color: var(--text-error, var(--color-red, #f44336));
}
}
@media only screen and (orientation: landscape) {
.is-phone .sr-card-container {
Expand Down