image-captions

README

GitBook Image Captions Plugin

Add nice generated captions to your book images. This plugin converts alt or title attributes of your images into the captions. Works on both the GitBook website and your own generated book (pdf, mobi).

_PAGE_IMAGE_NUMBER_: sequence number of the image in the chapter. First image in chapter gets value 1.

_BOOK_IMAGE_NUMBER_: sequence number of the image in the whole book. First image in book gets value 1.

Text alignment

The image caption is by default aligned to the center. You can override this setting by providing a config property align with one of the values:

left

right

This will align the caption to the left:

"pluginsConfig": {
"image-captions": {
"align": "left"
}
}

Image specific captions

You can set up caption template for a specific image by image level. Level is constructed from page level and image order so that on subpage 1.2 second image level is: 1.2.2. That can be used as an index on configuration:

First, you have to create your own css file - for example website.css. Then add
your definitions of figure and caption. You can change the text align, colors,
borders and so one. Last step is to attach your css style to the book. Open the book.json
config file and modify it to look similar to this:

Under the hood

This plugin attaches itself to the "page" event of GitBook generate task. It receives rendered HTML page of the chapter.
Then the plugin goes through the HTML code of the page, searching for images. If there is any image detected, containing also
alt or title atribute, the plugin replaces image occurences with the figure tag, including original
image and additional figcaption tag with the text read from image attributes.

Tests

Important part of this plugin is the test suite. You can run the test with command:

npm test

The test suite includes JSHint validation of the plugin and test suite itself.
Then the Mocha integration tests are executed, validating expected plugin bahavior.
Integration tests use gitbook-tester.