🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

gitbook-plugin-jazer

Package Overview
Dependencies
Maintainers
2
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gitbook-plugin-jazer

Gitbook exercises validated through a XRegExp and Javascript (work in progress)

Source
npmnpm
Version
1.0.47
Version published
Weekly downloads
4
Maintainers
2
Weekly downloads
 
Created
Source

Gitbook-Plugin-Jazer - REGEXP

version

Warning! This is a test version.

This is work in development. Use it at your own risk.

What is this

This is a plugin example for gitbook and allows you to:

  • Create {% regexp %} exercises: The answer to the posed question is validated using a regular expresion written by the gitbook author (Using XRegExp)
  • Create {% questionjs %} exercises: The answer to the psoed question is validated using a JavaScript function written by the gitbook author

Install

To use the jazer plugin in your Gitbook project, add the jazer plugin to the book.json file, then install the plugins using gitbook install.

{
    "plugins": ["jazer"]
}

Regexp questions

Simple regexp question example

{% regexp %}
¿Who discovered America?
{% solution %}
Christopher Columbus
{% validation %}
/(\s*(Crist[oó]bal\s+)?Col[oó]n\s*)|((Christopher\s+)?Columbus)/i
{% endregexp %}

regexp example using XRegExp:

You can also use XRegExp:

{% regexp %}
Who were the Spanish kings when America was discovered?
{% solution %}
Catholic Monarchs, also called Catholic Kings, or Catholic Majesties, Spanish Reyes Católicos, Ferdinand II of Aragon and Isabella I of Castile
{% validation %}
/
  (Catholic\s+Monarchs)            |
  (Catholic\s+Kings)               |
  (Catholic\s+Majesties)           |
  ((Spanish)?\s+Reyes\s+Católicos) |
  (Ferdinand(\s+II)?(\s+of\s+Aragon)?(\s+and)?(\s+Isabella)(\s+I)?(\s+of\s+Castill?e) |
  (Isabella)(\s+I)?(\s+of\s+Castill?e)(\s+and)?\s+(Ferdinand(\s+II)?(of\s+Aragon)?
/ix
{% endregexp %}

Questionjs exercises

{% questionjs  width="30%", height="10%", color="#BB504B"%}
Who were the Spanish kings when America was discovered?
{% solution %}
Catholic Monarchs, also called Catholic Kings, or Catholic Majesties, Spanish Reyes Católicos, Ferdinand II of Aragon and Isabella I of Castile
{% validation %}
function(answer) {
  if (answer.match(/Catholic\s+(Monarchs|Kings|Majesties)/i)) return true;
  if (answer.match(/(Spanish\s+)?Reyes\s+Cat[oó]licos/i)) return true;
  if (answer.match(/isabel|isabella/i && respuesta.match(/fernando|ferdinand/i) )) return true;
}
{% endquestionjs %}

Parameters

For each exercise you can specify four parameters: width, height, color and gutter

{% questionjs  width="30%", height="10%", color="#BB504B", gutter="true"%}
  • The width and height must be a percentage,
  • color can be any CSS valid value and
  • gutter must be true or false (whether to show or not the gutter).

You can specify the same parameters globally for all exercises with the book.json file

{

  "plugins": ["jazer"],

  "pluginsConfig":{
      "jazer": {
          "width": "80%",
          "height": "20%",
          "color": "#BB504B",
          "gutter": "false"
          "support": ["https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js","https://ajax.googleapis.com/ajax/libs/mootools/1.6.0/mootools.min.js"]
      }
  }

}

Book.json has a fifth parameters and allow you to load support librarys for questionjs blocks

Block parameters has priority over book.json parameters.

Errors

  • For regexp questions an alert window will open in case the XRegExp has errors.
  • For questionjs questions an alert window will open in case the function code has errors.

Example of regexp question having errors

In the following regular expression the open parenthesis has no matching closing parenthesis:

{% regexp %}
¿Quienes reinaban en España cuando se descubrió America?
{% solution %}
Los Reyes Católicos
{% validation %}
/
  (Isabel\s+                    # paréntesis abrir
  y
  \s+Fernando                   # sin
|
  Reyes\s+Cat[oó]licos          # paréntesis cerrar
/ix
{% endregexp %}

When the plugin is processed it emits an alert with the error message:

error message: bad regexp

Keywords

gitbook

FAQs

Package last updated on 07 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts