I like to write Markdown documents, so how do I put together Markdown documents?

This article shares a way to organize Markdown documents using GitBook. Let’s learn about it.

Markdown is a lightweight markup language. People just need to write a document in plain text, add dots, and it can be turned into a formatted document (like HTML rich text). Has been widely used in notes, documents, blogs, books and so on. In 2016, RFC 7763 also introduced the MIME type text/markdown.

1 Preparing Tools

  1. Installation Node. Js: nodejs.org/
  2. Install GitBook: www.npmjs.com/package/git…
npm install gitbook-cli -g
Copy the code

Finally, the terminal can execute gitbook:

$gitbook -v CLI version: 2.3.2 gitbook version: 3.2.3Copy the code

2 Preparing Documents

2.1 Creating a Document Directory

mkdir start-gitbook
Copy the code

2.2 Creating a Description FileREADME.md

Readme.md is a required file for GitBook

echo "# My GitBook" > README.md
Copy the code

2.3 Creating Directory FilesSUMMARY.md

SUMMARY. Md is a required file 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
Copy the code

Edit the Markdown document path that already exists in the organization. For a new project, write the desired document structure.

2.4 Creating a document structure

Create the document structure for the new project according to summary.md.

$ 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
Copy the code

2.5 Previewing documents

$ 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 successin 0.5s !

Starting server ...
Serving book on http://localhost:4000
Copy the code

Open the browser http://localhost:4000 to preview. The effect is as follows:

3 Generating Documents

By default, HTML documents are generated in the _book directory. If you want to generate other formats, you need to install the ebook-Convert plug-in.

3.1 installationebook-convertThe plug-in

Install Calibre: calibre-ebook.com/download, and configure the terminal ebook-convert command.

Ubuntu direct installation:

sudo aptitude install calibre
Copy the code

MacOS download and install, and configure soft link:

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

Finally, ebook-convert can be executed on the terminal:

$ebook-convert --version ebook-convert (Calibre 4.17.0) Created by: Kovid Goyal <[email protected]>Copy the code

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 successin 5.7s !
info: >> 1 file(s) generated
Copy the code

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 successin 1.9s !
info: >> 1 file(s) generated
Copy the code

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 successin 1.6s !
info: >> 1 file(s) generated
Copy the code

3.5 PDF Preview Effect

conclusion

Go coding!


Share practical tips and knowledge in Coding! Welcome to pay attention and grow together!