Skip to main content

MkDocs plugin for multiple choice quizzes

Project description

MkDocs MCQ Plugin

An interactive plugin for MkDocs to create and display single and multiple-choice quizzes directly within your documentation.

📖 View Live Demo

Features

  • Multiple Question Types: Supports both single choice (radio buttons) and multiple choice (checkboxes) questions.
  • Rich Content: Use standard Markdown within questions, answers, and feedback, including inline code, links, bold/italic text, and even multi-line code blocks.
  • Math Support: Render mathematical equations using LaTeX syntax in questions and answers with inline ($x^2$) and display ($$\int_0^1 x dx$$) math.
  • Immediate Feedback: Users get instant results after submitting an answer, with clear visual indicators for CORRECT, INCORRECT, and MISSED states.
  • Explanations/Details: Provide detailed feedback for any answer choice to help users learn.
  • Theme Agnostic: Uses embedded SVG icons to ensure a consistent and polished look on any MkDocs theme, not just Material for MkDocs.
  • Quiz Summary: Automatically calculates and displays a final score in a styled admonition block after submission.

Installation

Install the plugin using pip:

pip install mkdocs-mcq

Note: This plugin requires the following packages to be present in your MkDocs environment.

  • mkdocs>=1.5
  • pymdown-extensions>=10.0
  • pyyaml>=6.0

Configuration

To use the plugin, add mcq to the plugins section of your mkdocs.yml file. The plugin will automatically configure its dependencies.

plugins:
  - mcq

Usage: Authoring Quizzes

To create a quiz, use a fenced code block with the language identifier mcq.

Basic Structure

Each quiz block consists of two parts: a YAML configuration block and the question content written in Markdown's task list format.

```mcq
---
type: single
question: Your question text goes here.
---

- [ ] An incorrect answer.
- [x] The correct answer.
- [ ] Another incorrect answer.
```

Configuration Options

  • question (required): The question to be displayed. You can use Markdown here, like inline code.
  • type (required): The type of question. Must be either "single" or "multiple".

### Choices

Choices are defined using Markdown's task list syntax.

Use - [ ] for an incorrect answer.
Use - [x] for a correct answer.

Adding Feedback

To add detailed feedback to any choice, place it in a blockquote (>) immediately following the choice.

Note: Do not include markers like "CORRECT", "Incorrect Answer", etc. in your feedback text. The plugin automatically appends (CORRECT), (INCORRECT), or (MISSED) labels to the feedback based on the user's response.

- [x] 8
  > `**` is the exponentiation operator in Python.

- [ ] 6
  > The `**` operator is for exponents, not multiplication.

Math Equations

You can include mathematical equations in questions, choices, and feedback using LaTeX syntax.

Inline math: Use single dollar signs: $E = mc^2$ renders as $E = mc^2$

Display math: Use double dollar signs for block equations:

$$
\int_0^1 x^2 dx = \frac{1}{3}
$$

Example:

```mcq
---
type: single
question: What is the derivative of $f(x) = x^2 + 3x + 5$?
---

- [x] $f'(x) = 2x + 3$
  > Correct! Using the power rule: $\frac{d}{dx}(x^2) = 2x$ and $\frac{d}{dx}(3x) = 3$

- [ ] $f'(x) = x + 3$
  > This is incorrect. You need to apply the power rule to each term.
```

Examples

Here are some complete examples demonstrating the plugin's features.

Example 1: Single-Choice Question

This example demonstrates a simple single-choice question with feedback for each option.

```mcq
---
type: single
question: What is the output of `print(2 ** 3)`?
---

- [ ] 6
  > `2 * 3` would be 6.

- [x] 8
  > `**` is the exponentiation operator in Python.

- [ ] 9
- [ ] 5
```

Example 2: Multiple-Choice with Code Blocks

This example shows a multiple-choice question where the options themselves are multi-line code blocks.

```mcq
---
type: multiple
question: Which of the following are valid Python code? (Select all that apply)
---

- [ ]
  ```python
  echo("Hello World!")
  ```
  > `echo` is not a valid Python function

- [x] 
  ```python
  print("Hello World!")
  ```
  > `print` is a valid Python function

- [ ] 
  ```python
  printf("Hello World!")
  ```
  > `printf` is not a valid Python function

- [ ] 
  ```python
  println("Hello World!")
  ```
  > `println` is not a valid Python function
```

Example 3: Fenced-code block question

```mcq
---
type: single
question: |
  What is the error in the following Python code?
  ```python
  a = 10
  b = "5"
  print(a + b)
  ```
---

- [ ] A `SyntaxError`, because the code is improperly formatted.
  > The syntax of the code is valid Python.

- [x] A `TypeError`, because you cannot add an integer and a string.
  > The `+` operator is not defined between the types `int` and `str`, which raises a `TypeError`.

- [ ] No error, it will print `15`.
  > Python does not automatically convert the string `"5"` to a number in this context.

- [ ] No error, it will print `105`.
  > While some languages might concatenate these, Python raises a `TypeError` instead.
```

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mkdocs_mcq-0.2.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkdocs_mcq-0.2.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs_mcq-0.2.0.tar.gz.

File metadata

  • Download URL: mkdocs_mcq-0.2.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mkdocs_mcq-0.2.0.tar.gz
Algorithm Hash digest
SHA256 126acbd8903a5da5bcd3c0135f3bf46f45ff37287d3a5b4ccbb3bd602e6765ca
MD5 adfe6420b04c4dcf08ab40117bb509f2
BLAKE2b-256 daa5b1495b5b9f167c7fb2a5b6ba55872847d2c80d4a440537610d8de64e1e4a

See more details on using hashes here.

File details

Details for the file mkdocs_mcq-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mkdocs_mcq-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mkdocs_mcq-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1cf30b10e0d250eec00f7446831e0ab4d23cbf0c7b1780fa2432b8cdc45506e1
MD5 d58072e8a5a304da6d05248f7bc2ca12
BLAKE2b-256 2a505c517bf2fe1224c2bbe6e920654d30c82a9d9e810ba9f3bb42ab4d95a587

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page