https://github.com/gitbookio/plugin-exercises
Interactive exercices in a gitbook
https://github.com/gitbookio/plugin-exercises
Last synced: 3 months ago
JSON representation
Interactive exercices in a gitbook
- Host: GitHub
- URL: https://github.com/gitbookio/plugin-exercises
- Owner: GitbookIO
- License: apache-2.0
- Created: 2014-08-10T20:41:56.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2018-03-28T12:18:38.000Z (almost 8 years ago)
- Last Synced: 2025-04-25T06:39:20.118Z (9 months ago)
- Language: JavaScript
- Homepage: http://plugins.gitbook.com/plugin/exercises
- Size: 1 MB
- Stars: 56
- Watchers: 4
- Forks: 29
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Interactive exercises in a gitbook
==============
With this plugin, a book can contain interactive exercises (currently only in Javascript). An exercise is a code challenge provided to the reader, who is given a code editor to write a solution which is checked against the book author's validation code.
## How to use it?
To use the exercises plugin in your Gitbook project, add the `exercises` plugin to the `book.json` file, then install plugins using `gitbook install`.
```
{
"plugins": ["exercises"]
}
```
## Exercises format
An exercise is defined by 4 simple parts:
* Exercise **Message**/Goals (in markdown/text)
* **Initial** code to show to the user, providing a starting point
* **Solution** code, being a correct solution to the exercise
* **Validation** code that tests the correctness of the user's input
* **Context** (optional) code evaluated before executing the user's solution
```
{% exercise %}
Define a variable `x` equal to 10.
{% initial %}
var x =
{% solution %}
var x = 10;
{% validation %}
assert(x == 10);
{% context %}
// This is context code available everywhere
// The user will be able to evaluate `exposedVar`
var exposedVar = 3;
// ... or call `exposedFunction`
function exposedFunction {
return 3;
}
{% endexercise %}
```
**The old format (`gitbook < 2.0.0`) is no longer supported.**