Package detail

gitbook

GitbookIO12.6kApache-2.0deprecated2.6.9

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

Library and cmd utility to generate GitBooks

git, book, gitbook

readme

GitBook

NPM version Linux Build Status Windows Build status Slack Status

GitBook is a command line tool (and Node.js library) for building beautiful books using GitHub/Git and Markdown (or AsciiDoc). Here is an example: Learn Javascript.

You can publish and host books easily online using gitbook.com. A desktop editor is also available.

Check out the GitBook Community Slack Channel, Stay updated by following @GitBookIO on Twitter or GitBook on Facebook.

Complete documentation is available at help.gitbook.com.

Image

How to use it:

GitBook can be installed from NPM using:

$ npm install gitbook-cli -g

Create the directories and files for a book from its SUMMARY.md file (if existing) using

$ gitbook init

You can serve a repository as a book using:

$ gitbook serve

Or simply build the static website using:

$ gitbook build

Features

Output Formats

GitBook can generate your book in the following formats:

  • Static Website: This is the default format. It generates a complete interactive static website that can be, for example, hosted on GitHub Pages.
  • eBook: You need to have ebook-convert installed. You can specify the eBook filename as the second argument, otherwise book will be used.
    • Generate a PDF using: gitbook pdf ./myrepo ./mybook.pdf
    • Generate a ePub using: gitbook epub ./myrepo ./mybook.epub
    • Generate a MOBI using: gitbook mobi ./myrepo ./mybook.mobi
  • JSON: This format is used for debugging or extracting metadata from a book. Generate this format using: gitbook build ./myrepo --format=json.

Book Format

A book is a Git repository containing at least 2 files: README.md and SUMMARY.md.

README.md

Typically, this should be the introduction for your book. It will be automatically added to the final summary.

SUMMARY.md

The SUMMARY.md defines your book's structure. It should contain a list of chapters, linking to their respective pages.

Example:

# Summary

This is the summary of my book.

* [section 1](section1/README.md)
    * [example 1](section1/example1.md)
    * [example 2](section1/example2.md)
* [section 2](section2/README.md)
    * [example 1](section2/example1.md)

Files that are not included in SUMMARY.md will not be processed by gitbook.

Multi-Languages

GitBook supports building books written in multiple languages. Each language should be a sub-directory following the normal GitBook format, and a file named LANGS.md should be present at the root of the repository with the following format:

* [English](en/)
* [French](fr/)
* [Español](es/)

You can see a complete example with the Learn Git book.

Glossary

Allows you to specify terms and their respective definitions to be displayed in the glossary. Based on those terms, gitbook will automatically build an index and highlight those terms in pages.

The GLOSSARY.md format is very simple :

# term
Definition for this term

# Another term
With it's definition, this can contain bold text and all other kinds of inline markup ...

Variables and Templating

A set of variables can be defined in the book.json:

{
    "variables": {
        "host": "mybook.com"
    }
}

These variables can be used in the markdown files:

The host is {{ book.host }}

You can also use condition with these variables:

{% if book.host == "mybook.com" %}

{% else %}

{% endif %}

Variables of book.json are available in the book namespace. You can also access informations about the file itself and the gitbook version:

My file is {{ file.path }}
Modified at {{ file.mtime }}
Book built with GitBook {{ gitbook.version }}

Content References

You can use "content references," or conrefs, when writing books or documentation using GitBook.

Include a file from the same book:

{% include "./test.md" %}

or from a git repository (with a specific revision):

{% include "git+https://github.com/GitbookIO/documentation.git/README.md#1.0.1" %}

Includes can be used with variables (see Variables and Templating):

{% include book.ref_doc_readme %}

Ignoring files & folders

GitBook will read the .gitignore, .bookignore and .ignore files to get a list of files and folders to skip. (The format inside those files follows the same convention as .gitignore).

Best practices for the .gitignore is to ignore build files from node.js (node_modules, ...) and build files from GitBook: _book, *.epub, *.mobi and *.pdf (Download GitBook.gitignore).

Cover

A cover image can be set by creating a file: /cover.jpg. The best resolution is 1800x2360. The generation of the cover can be done automatically using the plugin autocover.

A small version of the cover can also be set by creating a file: /cover_small.jpg.

AsciiDoc

Since version 2.0.0, AsciiDoc can be used instead of Markdown, simply replace the .md by the .adoc extension. Chapters in the summary are detected from an ordered list in the SUMMARY.adoc.

Publish your book

The platform GitBook.com is like an "Heroku for books": you can create a book on it (public, paid, or private) and update it using git push.

Plugins

Plugins can be used to extend your book's functionality. Read GitbookIO/plugin for more information about how to build a plugin for GitBook.

Plugins needed to build a book can be installed using: gitbook install ./. You can find plugins at plugins.gitbook.com.

Debugging

You can use the options --log=debug and --debug to get better error messages (with stack trace). For example:

$ gitbook build ./ --log=debug --debug

How to use the latest commit from GitBook in gitbook-cli

To use the latest commit from GitBook/gitbook with gitbook-cli:

$ git clone https://github.com/GitbookIO/gitbook.git ./gitbook
$ gitbook versions:link ./gitbook

Now gitbook-cli will be using the ./gitbook folder.

You can uninstall it using: gitbook versions:uninstall latest.

changelog

Release notes

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

2.6.7

  • Fix bug with filenames including spaces
  • Add Turkish and Catalan translations

2.6.6

  • Fix custom CSS that are generated by plugins for PDF output

2.6.5

  • Fix support for plugins generating custom stylesheets (styles-less and styles-sass)
  • Fix glossary terms being replaced in script (ex: math)

2.6.4

  • Fix regression introduced by 2.6.3 of single HTML tags in markdown

2.6.3

  • Fix parsing bug with inline HTML in Markdown

2.6.2

  • Fix gitbook.state.bookRoot, gitbook.state.root now has a trailing slash
  • Update nunjucks to 2.2.0

2.6.1

  • Use CamelCase for gitbook.state.innerLanguage

2.6.0

  • Close sidebar after clicking a link on mobile
  • Add root for multilingual books: gitbook.state.bookRoot
  • Fix color of h6 headings
  • Fix bottom margin of lists and blockquotes
  • Add Swedish translation (sv)
  • Add Czech translation (cs)
  • Fix locale names for zh-hans and jp
  • Update plugin search to fix crashes
  • Aceept case-incensitive structure files (README, GLOSSARY, etc)

2.5.2

  • Fix custom stylesheets for ebook generation
  • Trigger event start before page.change

2.5.1

  • Fix calcul of gitbook.state.root when serving HTML index as /

2.5.0

  • Font settings, sharing and search are externalized as default plugins
  • Plugins can define a configuration schema in the manifest, this schema will be used to validate configuration during build
  • New Node.js API for plugin: book.formatString(type, content)
  • New client side API for website plugins: gitbook.toolbar.createButton(opts)
  • Better header/footer for PDF, CSS wil be inlined to easily style the header/footer
  • Cleaner table of contents for ebooks
  • Support for RTL in ebook's table of contents
  • Better colors for mobi (links and code blocks)
  • Fix installation of plugins when using a pre-release
  • Fix support for pre-releases
  • Update asciidoc parser to remove git dependency
  • Fix templating in imported content
  • Fix querystring in image urls
  • Normalize heading IDs like GitHub
  • Use Arial as default font for PDFs
  • Add root, chapterTitle and filepath to gitbook.state JS API

2.4.3

  • Add ukrainian translation (uk)
  • Add book.json configuration for maximum size of search index
  • Improve reliability of summary parser

2.4.2

  • Default plugins should not be installed by gitbook install
  • Limit search index size to avoid crash during generation
  • Fix code highlighting for html without language specified
  • Fix warning message for gitbook version when building a multilingual book

2.4.1

  • Fix disabling of default plugins, ex: -highlight

2.4.0

  • Fix page being updated when user wants to open a link in a new tab
  • Plugins can now replaced default code highlighter
  • Add semantic information for screen readers (web version)
  • Content references accept absolute paths, resolved to book folder
  • Improve overall reliability

2.3.3

  • Fix bug in SUMMARY parsing preventing multiple entries without filenames

2.3.2

  • Fix blocks (like maths) in Asciidoc
  • Fix error when checking gitbook version

2.3.1

  • Fix black font color for ebooks (mobi, pdf and epub)
  • Fix ISO code for korean language
  • Fix korean translation
  • Fix syntax highlighting for asciidoc
  • Fix inline html escaping in markdown
  • Add warning for file outside SUMMARY
  • Force SUMMARY entries to be unique by filename

2.3.0

  • Fix nunjucks issue with multiple {% raw %} blocks
  • Fix crash when git conref failed
  • Fix crash when failed to download remote image (better error message)
  • Fix flicking effect when changing page (big UX improvement)
  • Add Hebrew translation (he)
  • Add utility method book.config.get for plugins
  • Hooks page:before and page are no longer deprecated
  • Remove webfonts to make website lighter
  • Make glossary's order case insensitive

2.2.0

  • Fix direction in code blocks (always LTR)
  • Add options chapterMark and pageBreaksBefore for PDF
  • Update code highlighting library
  • book.json accessible as config in templating syntax
  • Add Vietnamese translation (vi)

2.1.0

  • Fix error in calcul of levels in table of contents, error introduced a few versions ago
  • Add optional styles/print.css to replace print.css used in ebook

2.0.4

  • Fix {% raw %}, got confused with "fake" variable declarations
  • Fix title of language chooser
  • Fix the X-UA-Compatible meta tag
  • Move style sheets to the <head> section

2.0.3

  • Fix gitbook init for SUMMARY with empty entries
  • Fix escaping of code blocks in markdown

2.0.2

  • Fix relative links in windows
  • Improve watcher in serve command (switch to chokidar)
  • Add Romanian translation (ro)
  • Add Finish translation (fi)
  • Add Japanese translation (jp)
  • Add Korean translation (kr)

2.0.1

  • Improve error logging (display file, line and column)
  • Add back support for options.originalInput
  • Don't process math in markdown parser (delegated to mathjax plugin)
  • Fix some cases of code blocks escaping
  • Fix i18n for introduction title in json format
  • Fix reload when book configuration is updated
  • Fix backslashes in url when building on windows

2.0.0

  • Fix page title of introduction
  • Ignore codeblocks when replacing glossary terms
  • Improve Unit Tests
  • Fix scrolling position in website when preparing page

2.0.0-beta.5

  • Fix progress order in json format

2.0.0-beta.4

  • Fix default generator for use programmatically
  • Add option "author" for html meta tags
  • Fix links normalization (content and hash)

2.0.0-beta.3

  • Fix odd cases with code blocks escaping

2.0.0-beta.2

  • Fix definition of entry point title using SUMMARY.md

2.0.0-beta.1

  • Fix windows incompatibility
  • Add support for rtl (enabled by default for ar and fa)
  • Escape code blocks in markdown parser
  • Add Persian/Farsi translation (fa)
  • Add Arabic translation (ar)
  • Add Bengali translation (bn)
  • Provide generator name in template context

2.0.0-alpha.9

  • Fix links in sidebar
  • Fix normalization of html link (README to index)
  • Fix html snippets escaping

2.0.0-alpha.8

  • Improve locale detection for i18n
  • Fix chapter name for Glossary in pdf
  • Don't escape html in glossary items
  • Fix generation of multilingual book as ebook
  • Add "post" block attribute to post-process

2.0.0-alpha.7

  • Fix display of glossary in ebook formats
  • Add default footer and header to pdf
  • Fix generation of json format compatible with 1.x.x
  • Add Simplifiled Chinese and Traditional Chinese translations

2.0.0-alpha.6

  • Add es and pt translations
  • Fix replacement of glossary terms

2.0.0-alpha.5

  • Fix copy of files/covers
  • Add back finish:before hook

2.0.0-alpha.4

  • Fix copy of cover for multilingal books

2.0.0-alpha.3

  • Norwegian translation
  • Load plugins from book in priority

2.0.0-alpha.3

  • Fix init command
  • Update parsers to fix spaces in summary (gitbook-parsers@0.3.1)

2.0.0-alpha.1

  • Externalize parsing into gitbook-parsers module
  • Supports AsciiDoc and reStructuredText
  • Hooks for page (page:*) are now deprecated, plugins should extend filters and blocks instead
  • Hooks summary and glossary (after and before) have been removed
  • Exercises and Quizzes are no longer parsed in the markdown parser
  • Support for more markdown extensions: .markdown, .mdown
  • Templates are rendered with nunjucks instead of swig, syntax is almost compatible, there is some changes with contexts and filters. {{ super() }} should be use instead of {% parent %}
  • Clean output folder on build without removing .git and .svn
  • MathJAX is no longer a default plugin
  • SVG images are converted to PNG during generation of ebooks
  • i18n in website and ebook (ru, it, de, fr)
  • New templating syntax
  • Content references (both internal and external)
  • Glossary terms are handled during generation (also in ebook format)

1.5.0

  • Fix serve command, broken by 1.4.2
  • Add nicer dark theme :)

1.4.2

  • Force process.exit after builds, to prevent (possibly) lingering plugins

1.4.1

  • Fix command 'install' without arguments

1.4.0

  • Add command gitbook install to install plugins from book.json
  • package.json is no longer necessary

1.3.4

  • Add glossary to ebooks
  • Fix autocover with new hook "finish:before"
  • Add X-UA-Compatible meta tag for IE

1.3.3

  • Fix parsing of lexed content using the client library

1.3.2

  • ePub files are now passing validation from epubcheck
  • Fix replacement of multiple glossary terms in a single sentence
  • Fix on windows deep relative links
  • Fix search indexer

1.3.1

  • Fix error with links in markdown

1.3.0

  • Bundle gitbook parsing library as a client side library in gitbook.js and gitbook.min.js

1.2.0

  • Improvements on ebook generation
  • Fix incorrect follow of links in ebook generation
  • Move Table of Contents at the beginning of the ebook
  • Update to last highlight.js (includes Swift)
  • Includes of templates and variables (from book.json)

1.1.1

  • Rewrite quiz logic to be more robust
  • Improve integration of glossary
  • Improve generation of ebook by using a multiple HTML pages input source
  • Fix incorrect page breaks after h1 and h2 divs
  • New options to set header and footer in PDF generation

1.1.0

  • Plugins can now extend the ebook generation (pdf, epub, mobi)
  • Update kramed to version 0.4.3

1.0.3

  • Update mathjax plugin and MathJAx to version 2.4
  • Update highlight.js to 8.2.0

1.0.2

  • Update mathjax plugin, fixes issues with inline math rendering (no longer wanted)

1.0.1

  • New inline math convention (kramdown's), using $$ rather than $ as delimiters
  • Fix instapaper sharing
  • The exercises & quizzes plugins are now by default

1.0.0

  • New design
  • Support for glossary
  • Support for sharing to instapaper
  • Support for footnotes

0.7.1

  • Update fs-extra to 0.10.0 (fixes potential race conditions)

0.7.0

  • Add page break in ebook (pdf, epub, mobi) between chapters/articles
  • Start using kramed instead of marked
  • Fix display of inline math
  • Switch to graceful-fs to fix EMFILE errors
  • Add sharing to weibo.com

0.6.2

  • Support generating a plugin's book info dynamically
  • Improve navigation on dark theme
  • Improve path normalization when parsing SUMMARY.md

0.6.0

  • Generate header id the same as github
  • Custom links can be added at top of sidebar
  • Summary can now be transformed by plugins
  • Support importing code snippets