Tip: organize markdown documents with gitbook

Time:2020-10-26

If you like to write documents with markdown, how can you put them together?

This article shares a way to organize markdown documents with gitbook. Let’s get to know it.

Markdown is a lightweight markup language. People only need to write a document in plain text, and add a dot mark to it, then it can be converted into a formatted document (such as HTML rich text). It has been widely used in notes, documents, blogs, books and so on. In 2016, RFC 7763 also introduced the MIME typetext/markdown

1 Preparation Tools

  1. Installation Node.js :https://nodejs.org/
  2. Install gitbook:https://www.npmjs.com/package…
npm install gitbook-cli -g

Finally, it is executable in the terminalgitbook :

$ gitbook -V
CLI version: 2.3.2
GitBook version: 3.2.3

2 preparation of documents

2.1 create document directory

mkdir start-gitbook

2.2 create documentationREADME.md

README.mdIt’s a necessary document for gitbook

echo "# My GitBook" > README.md

2.3 create directory fileSUMMARY.md

SUMMARY.mdIt’s a necessary document for gitbook

cat <<EOF > SUMMARY.md
# 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)
EOF

Edit the existing markdown document path of the organization. For new projects, the expected document structure is written.

2.4 create document structure

according toSUMMARY.mdTo create a document structure for the new project.

$ gitbook init
info: create section1/README.md
info: create section1/example1.md
info: create section1/example2.md
info: create section2/README.md
info: create section2/example1.md
info: create SUMMARY.md

2.5 preview document

$ gitbook serve
Live reload server started on port: 35729
Press CTRL+C to quit ...

info: 7 plugins are installed
info: loading plugin "livereload"... OK
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 6 pages
info: found 0 asset files
info: >> generation finished with success in 0.5s !

Starting server ...
Serving book on http://localhost:4000

Browser openhttp://localhost: 4000. The results are as follows:

Tip: organize markdown documents with gitbook

3 generating documents

By default, HTML documents are generated_bookcatalog. If you want to generate other formats, you need to installebook-convertplug-in unit.

3.1 installationebook-convertplug-in unit

Install calibre:https://calibre-ebook.com/dow…And configure the terminalebook-convertCommand.

Ubuntu direct installation:

sudo aptitude install calibre

Download and install MacOS, and configure the soft link:

ln -s /Users/John/Applications/calibre.app/Contents/MacOS/ebook-convert /usr/local/bin

Finally, it is executable in the terminalebook-convert :

$ ebook-convert --version
ebook-convert (calibre 4.17.0)
Created by: Kovid Goyal <[email protected]>

3.2 generating PDF documents

$ gitbook pdf ./ ./mybook.pdf
info: 7 plugins are installed
info: 6 explicitly listed
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 6 pages
info: found 1 asset files
info: >> generation finished with success in 5.7s !
info: >> 1 file(s) generated

3.3 generating ePub documents

$ gitbook epub ./ ./mybook.epub
info: 7 plugins are installed
info: 6 explicitly listed
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 6 pages
info: found 1 asset files
info: >> generation finished with success in 1.9s !
info: >> 1 file(s) generated

3.4 generating Mobi documents

$ gitbook mobi ./ ./mybook.mobi
info: 7 plugins are installed
info: 6 explicitly listed
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 6 pages
info: found 1 asset files
info: >> generation finished with success in 1.6s !
info: >> 1 file(s) generated

3.5 PDF preview effect

Tip: organize markdown documents with gitbook

epilogue

Go coding!


Share the practical tips and knowledge in coding! Welcome to concern and grow together!

Tip: organize markdown documents with gitbook

Recommended Today

Layout of angular material (2): layout container

Layout container Layout and container Using thelayoutDirective to specify the layout direction for its child elements: arrange horizontally(layout=”row”)Or vertically(layout=”column”)。 Note that if thelayoutInstruction has no value, thenrowIs the default layout direction. row: items arranged horizontally.max-height = 100%andmax-widthIs the width of the item in the container. column: items arranged vertically.max-width = 100%andmax-heightIs the height of the […]