Movatterモバイル変換


[0]ホーム

URL:


Keyboard shortcuts

Press or to navigate between chapters

PressS or/ to search in the book

Press? to show this help

PressEsc to hide this help

mdBook Documentation

    Creating a Book

    Once you have themdbook CLI tool installed, you can use it to create and render a book.

    Initializing a book

    Themdbook init command will create a new directory containing an empty book for you to get started.Give it the name of the directory that you want to create:

    mdbook init my-first-book

    It will ask a few questions before generating the book.After answering the questions, you can change the current directory into the new book:

    cd my-first-book

    There are several ways to render a book, but one of the easiest methods is to use theserve command, which will build your book and start a local webserver:

    mdbook serve --open

    The--open option will open your default web browser to view your new book.You can leave the server running even while you edit the content of the book, andmdbook will automatically rebuild the outputand automatically refresh your web browser.

    Check out theCLI Guide for more information about othermdbook commands and CLI options.

    Anatomy of a book

    A book is built from several files which define the settings and layout of the book.

    book.toml

    In the root of your book, there is abook.toml file which contains settings for describing how to build your book.This is written in theTOML markup language.The default settings are usually good enough to get you started.When you are interested in exploring more features and options that mdBook provides, check out theConfiguration chapter for more details.

    A very basicbook.toml can be as simple as this:

    [book]title = "My First Book"

    SUMMARY.md

    The next major part of a book is the summary file located atsrc/SUMMARY.md.This file contains a list of all the chapters in the book.Before a chapter can be viewed, it must be added to this list.

    Here’s a basic summary file with a few chapters:

    # Summary[Introduction](README.md)- [My First Chapter](my-first-chapter.md)- [Nested example](nested/README.md)    - [Sub-chapter](nested/sub-chapter.md)

    Try opening upsrc/SUMMARY.md in your editor and adding a few chapters.If any of the chapter files do not exist,mdbook will automatically create them for you.

    For more details on other formatting options for the summary file, check out theSummary chapter.

    Source files

    The content of your book is all contained in thesrc directory.Each chapter is a separate Markdown file.Typically, each chapter starts with a level 1 heading with the title of the chapter.

    # My First ChapterFill out your content here.

    The precise layout of the files is up to you.The organization of the files will correspond to the HTML files generated, so keep in mind that the file layout is part of the URL of each chapter.

    While themdbook serve command is running, you can open any of the chapter files and start editing them.Each time you save the file,mdbook will rebuild the book and refresh your web browser.

    Check out theMarkdown chapter for more information on formatting the content of your chapters.

    All other files in thesrc directory will be included in the output.So if you have images or other static files, just include them somewhere in thesrc directory.

    Publishing a book

    Once you’ve written your book, you may want to host it somewhere for others to view.The first step is to build the output of the book.This can be done with themdbook build command in the same directory where thebook.toml file is located:

    mdbook build

    This will generate a directory namedbook which contains the HTML content of your book.You can then place this directory on any web server to host it.

    For more information about publishing and deploying, check out theContinuous Integration chapter for more.


    [8]ページ先頭

    ©2009-2025 Movatter.jp