A Drupal 10+ module that automatically renders and displays quizzes generated by the Quiz Generator module with full MathJax support for mathematical expressions.
The QuizRen module automatically processes Quiz content type nodes and renders interactive quiz questions with mathematical notation support. When a Quiz node is viewed, the module fetches quiz data from an API endpoint, parses the content, and displays it in a user-friendly format.
- Automatic Rendering: Quiz content renders automatically when Quiz nodes are viewed
- API Integration: Fetches quiz data from
/api/v1/quiz/dataendpoint - MathJax v4 Support: Full support for LaTeX mathematical expressions
- Error Handling: Comprehensive error handling with graceful fallbacks
- Debug Logging: Console logging for troubleshooting
- Responsive Design: Clean, modern styling for quiz presentation
- Drupal 10.2+ or Drupal 11+
- Quiz Generator (quizgen) module
- Modern web browser with JavaScript enabled
- Place the module in
web/modules/custom/quizren/ - Enable the module:
drush en quizren - Clear caches:
drush cr
The module automatically renders quizzes when Quiz content type nodes are viewed. Simply:
- Create or view a Quiz node
- Ensure there's a
<div id="render"></div>element on the page - The quiz will automatically load and display
Visit the test controller to debug quiz rendering:
/admin/config/quizren/test/[NODE_ID]
Replace [NODE_ID] with the ID of a Quiz node.
- Purpose: Handles API communication with quiz data endpoint
- Methods:
fetchQuizData($nid): Retrieves quiz data from API
- Dependencies: HTTP client, logger, config factory
- Purpose: Parses and validates quiz data from API responses
- Methods:
parseQuizData($api_data): Parses field_quiz_data JSONprocessQuestion($question, $index): Validates individual questions
- Dependencies: Logger factory
- Purpose: Frontend quiz rendering and MathJax integration
- Key Functions:
fetchQuizData(): API communicationparseQuizData(): Client-side data parsingrenderQuiz(): HTML generation and DOM injectionprocessMathJax(): Mathematical expression rendering
- Purpose: MathJax v4 configuration
- Features:
- Inline math:
\(and\)delimiters - Display math:
\[and\]delimiters - SVG rendering with global font cache
- Inline math:
[
{
"nid": "80",
"title": "Quiz Title",
"field_quiz_data": "HTML-encoded JSON string"
}
][
{
"question": "Question text with \\(LaTeX\\) expressions",
"choices": [
{
"id": "c1",
"text": "Choice text",
"is_correct": true
}
],
"feedback": {
"correct_feedback": "Correct answer explanation",
"incorrect_feedback": "Incorrect answer explanation"
}
}
]The module includes MathJax v4 with the following configuration:
- Inline Math:
\(and\)delimiters - Display Math:
\[and\]delimiters - Rendering: SVG with global font cache
- Processing: Escapes and environments enabled
.quiz-container: Main quiz wrapper.quiz-question: Individual question container.quiz-choices: Choice list styling.quiz-feedback: Feedback section styling.quiz-error: Error message styling
The module provides detailed console logging:
- API request/response data
- Parsing steps and results
- MathJax processing status
- Error messages and warnings
- No quiz data: Check API endpoint availability
- Math not rendering: Verify MathJax loading in browser console
- Missing render div: Ensure
<div id="render"></div>exists on page
quizren/
├── README.md
├── quizren.info.yml
├── quizren.module
├── quizren.services.yml
├── quizren.libraries.yml
├── quizren.routing.yml
├── src/
│ ├── Service/
│ │ ├── QuizApiService.php
│ │ └── QuizParserService.php
│ └── Controller/
│ └── QuizrenTestController.php
├── js/
│ ├── mathjax-config.js
│ └── quiz-renderer.js
└── css/
└── quiz-renderer.css
To customize quiz rendering:
- Override CSS classes for styling
- Extend JavaScript functions for custom behavior
- Modify services for additional data processing
- URL:
/api/v1/quiz/data - Method: GET
- Parameters:
nid(node ID) - Response: JSON array with quiz node data
- HTTP request failures
- JSON parsing errors
- Missing or invalid data structures
- MathJax loading issues
This module is part of the Synth OER project and follows Drupal licensing standards.
For issues and feature requests, please contact the development team or check the project documentation.