Skip to content

Conversation

@ewels
Copy link
Owner

@ewels ewels commented Nov 24, 2025

Fixes #9

claude and others added 12 commits November 16, 2025 10:48
Implements a new fill-in-the-blank question type using [[answer]] syntax,
as requested in issue #9. This allows quiz authors to create questions where
users type in answers rather than selecting from multiple choices.

Key features:
- Double square bracket syntax [[answer]] marks blanks in questions
- Supports single or multiple blanks per question
- Case-insensitive answer validation (trimmed and lowercased)
- Markdown formatting works around blanks
- HTML-escaped answers in data attributes for security
- Full integration with existing quiz features (content sections, progress tracking, localStorage)
- CSS styling for inline text inputs with visual feedback
- Shows correct answers as placeholders when show_correct is enabled

Implementation details:
- Plugin automatically detects quiz type based on content ([[...]] patterns)
- Python: New _process_fill_in_blank_quiz() method handles parsing and HTML generation
- JavaScript: Extended validation logic to compare input values with data-answer attributes
- CSS: New .quiz-blank-input styles for inline text fields
- Tests: 11 comprehensive tests covering various scenarios

All 57 tests passing.
Update fill-in-the-blank quiz processing to use horizontal rule (---)
as separator between question and optional content section. This allows
arbitrary markdown in the question area while maintaining clear separation
of the after-answer content.

Changes:
- Modified _process_fill_in_blank_quiz() to look for '---' separator
- Updated inline documentation and examples
- Added test for fill-in-blank with horizontal rule separator
- All 58 tests pass

Example:
<quiz>
The answer is [[foo]].

---
This content is only shown after answering.
</quiz>

Fixes #9
Add comprehensive documentation for fill-in-the-blank quiz type with
horizontal rule separator for optional content sections.

Changes:
- Added fill-in-the-blank section to examples.md with:
  - Single blank example
  - Multiple blanks example
  - Fill-in-blank with content using horizontal rule (---)
  - Complex example with markdown formatting
- Updated features list in README.md and index.md to mention fill-in-the-blank
- Updated CLAUDE.md to reflect horizontal rule separator

The horizontal rule (---) provides clear separation between question
and after-answer content, allowing arbitrary markdown in the question area.
Fix two issues with fill-in-the-blank quizzes:

1. Form interactivity bug: After incorrect submission, submit button is
   now kept visible (when disable_after_submit is false) so users can
   edit their answers and resubmit without clicking "Try Again" first.

2. Enhanced feedback: When show_correct is enabled, incorrect answers
   now show a bullet-pointed list with:
   - Each incorrect answer displayed with strikethrough
   - An arrow (→) pointing to the correct answer
   - Format: ~~wrong answer~~ → correct answer

Changes:
- quiz.js lines 857-898: Updated submit handler feedback
- quiz.js lines 619-672: Updated localStorage restoration feedback
- quiz.js lines 810-813: Clear innerHTML on reset
- quiz.js lines 157-161: Clear innerHTML on resetAll

All 58 tests pass including 12 fill-in-blank tests.
When localStorage restores an incorrect answer state on page load for
quizzes without content sections, the code threw "Cannot read property
'classList' of null" error, breaking ALL quiz functionality on the page.

The bug occurred because the code tried to access section.classList
without checking if the section element exists. Quizzes without content
sections (no <section> tag) have section === null.

Fixed by adding null checks before all section.classList operations:
- Line 595, 622, 696, 735: Restore state from localStorage
- Line 817: Reset handler
- Line 859, 923: Submit handler

This fixes the critical bug where entering a wrong answer on first page
load would break all quiz interactivity for every quiz on the page.

All 58 tests pass.
Resolved conflicts in mkdocs_quiz/js/quiz.js by:
- Keeping fill-in-blank implementation with detailed bullet-list feedback
- Adding translation support using t() function for all user-facing strings
- Maintaining null checks for section element to prevent JS errors

Changes:
- Wrapped "Correct answer!" with t() at lines 621, 896, 968
- Wrapped "Incorrect answer" messages with t() at lines 665, 904, 990
- Preserved fill-in-blank detailed feedback with strikethrough formatting

Merged changes include:
- Translation support (pt_BR, fr_FR) and TranslationManager
- CLI improvements for translation management
- Additional documentation for translations

All 58 tests pass including 12 fill-in-blank tests.
…cts)

Resolved merge conflicts and incorporated upstream improvements:

Conflicts resolved:
- CLAUDE.md: Merged fill-in-blank docs with markdown_extensions info
- mkdocs_quiz/plugin.py: Kept both fill-in-blank format and asterisk bullets note
- mkdocs_quiz/js/quiz.js: Kept fill-in-blank implementation, added bug fixes
- tests/test_plugin.py: Kept both fill-in-blank tests and new markdown_extensions tests

Bug fixes from upstream applied to quiz.js:
- Fix duplicate event handlers on Material instant navigation (f6271ca)
- Prevent page scroll to top when answering quizzes (03b2eac)
  - Added stopPropagation() to submit handler
  - Added preventDefault() to auto-submit change handler
  - Made submit events properly bubbleable and cancelable

Upstream changes merged:
- Translation system improvements (multiple new languages)
- Markdown extensions support in quiz content
- Asterisk bullet support (* [x] and * [ ])
- Various bug fixes and improvements

All 85 tests pass (1 skipped).
Fill-in-blank quizzes now properly use:
- Configured markdown extensions from mkdocs.yml for both question text
  and content sections (previously used default extensions only)
- Translation system for "Submit" button and "Question {n}" text
  (previously hardcoded in English)

Changes:
- Updated _process_fill_in_blank_quiz() signature to accept
  TranslationManager and MkDocsConfig parameters
- Pass config to convert_inline_markdown() and get_markdown_converter()
  for proper markdown extension support
- Use t.get() for translatable strings (Submit, Question {n})
- Added form attributes (action, onsubmit) for consistency with
  multiple-choice quizzes
- Added test_fill_in_blank_markdown_extensions() to verify markdown
  extension support

This ensures fill-in-blank quizzes have feature parity with
multiple-choice quizzes introduced in recent PRs.

All 86 tests pass (1 skipped).
- Add explicit type annotation for blank_match to resolve Optional[Match] error
- Rename variable from 'match' to 'blank_match' to avoid variable redefinition
- Apply prettier formatting to CLAUDE.md (add blank line for readability)
- All pre-commit checks now pass: ruff, prettier, mypy, translation checks
- All 86 tests pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New question type: fill in the blanks

3 participants