
Security News
Insecure Agents Podcast: Certified Patches, Supply Chain Security, and AI Agents
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.
gitbook-convert
Advanced tools
CLI to convert an existing document to a GitBook.
Install this globally and you'll have access to the gitbook-convert command anywhere on your system.
$ npm install gitbook-convert -g
$ gitbook-convert [options] <file> [export-directory]
| Short | Long | Description | Type | Default |
|---|---|---|---|---|
| -t | --document-title | Name used for the main document title | string | null |
| -a | --assets-dir | Name of the document's assets export directory | string | assets |
| -m | --max-depth | Maximum title depth to use to split your original document into sub-chapters | integer | 2 |
| -p | --prefix | Prefix filenames by an incremental counter | flag | false |
| -d | --debug | Log stack trace when an error occurs | flag | false |
After converting your document, the corresponding GitBook files will be placed in the provided export-directory folder. The folder is created during conversion.
If export-directory is not provided, a new export folder is created in the current working directory. The GitBook files are then placed here.
If the --document-title argument is not passed, the filename without the file extension will be used as the main document title.
| Type | Extension |
|---|---|
| Microsoft Office Open XML Document | .docx |
| OpenOffice / Open Document Format | .odt |
| Docbook Markup Language | .xml |
| HyperText Markup Language | .html |
This version of gitbook-convert generates markdown files only. Support for asciidoc might be added later.
gitbook-convert divides your original document into chapters and sub-chapters, if any, one per output file. To do this, gitbook-convert automatically detects the headers in your document and uses the -m flag to split it into sub-chapters.
When converting a Docbook file though, the depth is always detected automatically.
Thus, converting the following document named History of modern computers.docx with the default --max-depth flag:
Chapter 1
What the world used to be.
The beginning
At the beginning was the big bang...
The following
Strange creatures called “humans” had trouble living in peace...
Chapter 2
What the world is now.
The awakening
Computers came to rule the world...
The end
The power supply went disconnected.
will produce the following output:
user @ cwd/export/history_of_modern_computers
README.md
SUMMARY.md
assets/
chapter_1/
README.md
the_beginning.md
the_following.md
chapter_2/
README.md
the_awakening.md
the_end.md
While using 1 for --max-depth would produce:
user @ cwd/export/history_of_modern_computers
chapter_1.md
chapter_2.md
README.md
SUMMARY.md
assets/
The SUMMARY.md file is created automatically.
For our first example:
# Summary
* [Introduction](README.md)
* [Chapter 1](chapter_1/README.md)
* [The beginning](chapter_1/the_beginning.md)
* [The following](chapter_1/the_following.md)
* [Chapter 2](chapter_2/README.md)
* [The awakening](chapter_2/the_awakening.md)
* [The end](chapter_2/the_end.md)
With --max-depth set to 1:
# Summary
* [Introduction](README.md)
* [Chapter 1](chapter_1.md)
* [Chapter 2](chapter_2.md)
The content of the README.md file depends on your document structure. Anyways, the filename of your original document will be used as the main title here.
gitbook-convert creates the default GitBook README.md file:
# History of modern computers
This file serves as your book's preface, a great place to describe your book's content and ideas.
Otherwise, everything before the first main header is used as the README.md content. If we modify our example to be:
A short history of modern computers.
Chapter 1
The beginning
At the beginning was the big bang...
The following
...
The content of the README.md file will be:
# History of modern computers
A short history of modern computers.
The behavior is the same when --max-depth is set to higher levels. Each README.md in the sub-chapters folders will contain the preface for the current chapter.
The appropriate converter for a document type is deduced from its extension.
For now, the converters should:
lib/converters,/lib/converters/docx.js,lib/converters/index.js file for reference and use.The .docx converter uses mwilliamson's mammoth.js to convert your document to HTML before generating the output.
gitbook-convert will try to export your inline images in the /assets folder, using the image title as the image filename if provided.
The .odt converter uses odt2html to convert your document to HTML before generating the output. Because there was no node module out there to convert OpenOffice documents to HTML, we built our own.
gitbook-convert will try to export your inline images in the /assets folder, using the image name in the document as the image filename if provided.
gitbook-convert requires xsltproc to be installed to process a Docbook. If you are using MacOS or a Linux distribution, it should be installed by default.
You can test that xsltproc is installed using:
$ which xsltproc
xsltproc uses the last version of docbook.xsl to convert your Docbook to HTML first. Since the Docbook XML markup is very large, gitbook-convert will try to convert the meta-data as well as possible. Extended conversion might be added to the tool based on user requests.
When you install gitbook-convert using npm, the docbook.xsl stylesheets are downloaded and installed along with the app.
We recommend using the tool with Docbook version 5. Here is a walk-through for converting an existing Docbook in version 4 to version 5.
FAQs
Convert your existing books in different formats to GitBook
The npm package gitbook-convert receives a total of 4 weekly downloads. As such, gitbook-convert popularity was classified as not popular.
We found that gitbook-convert demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.

Security News
The planned feature introduces a review step before releases go live, following the Shai-Hulud attacks and a rocky migration off classic tokens that disrupted maintainer workflows.