diff --git a/docs/user-guide/writing-your-docs.md b/docs/user-guide/writing-your-docs.md index ec8390c8..4514451f 100644 --- a/docs/user-guide/writing-your-docs.md +++ b/docs/user-guide/writing-your-docs.md @@ -1,67 +1,16 @@ # Writing your docs -How to write and layout your markdown source files. +How to layout and write your Markdown source files. --- -## Configure Pages and Navigation - -The [pages configuration](/user-guide/configuration.md#pages) in your -`mkdocs.yml` defines which pages are built by MkDocs and how they appear in the -documentation navigation. If not provided, the pages configuration will be -automatically created by discovering all the Markdown files in the -[documentation directory](/user-guide/configuration.md#docs_dir). An -automatically created pages configuration will always be sorted -alphanumerically by file name. You will need to manually define your pages -configuration if you would like your pages sorted differently. - -A simple pages configuration looks like this: - -```no-highlight -pages: -- 'index.md' -- 'about.md' -``` - -With this example we will build two pages at the top level and they will -automatically have their titles inferred from the filename. Assuming `docs_dir` -has the default value, `docs`, the source files for this documentation would be -`docs/index.md` and `docs/about.md`. To provide a custom name for these pages, -they can be added before the filename. - -```no-highlight -pages: -- Home: 'index.md' -- About: 'about.md' -``` - -### Multilevel documentation - -Subsections can be created by listing related pages together under a section -title. For example: - -```no-highlight -pages: -- Home: 'index.md' -- User Guide: - - 'Writing your docs': 'user-guide/writing-your-docs.md' - - 'Styling your docs': 'user-guide/styling-your-docs.md' -- About: - - 'License': 'about/license.md' - - 'Release Notes': 'about/release-notes.md' -``` - -With the above configuration we have three top level sections: Home, User Guide -and About. Then under User Guide we have two pages, Writing your docs and -Styling your docs. Under the About section we also have two pages, License and -Release Notes. - ## File layout -Your documentation source should be written as regular Markdown files, and -placed in a directory somewhere in your project. Normally this directory will be -named `docs` and will exist at the top level of your project, alongside the -`mkdocs.yml` configuration file. +Your documentation source should be written as regular Markdown files (see +[Writing with Markdown](#writing-with-markdown) below), and placed in the +[documentation directory](configuration.md#docs_dir). By default, this directory +will be named `docs` and will exist at the top level of your project, alongside +the `mkdocs.yml` configuration file. The simplest project you can create will look something like this: @@ -75,7 +24,7 @@ By convention your project homepage should always be named `index`. Any of the following extensions may be used for your Markdown source files: `markdown`, `mdown`, `mkdn`, `mkd`, `md`. -You can also create multi-page documentation, by creating several markdown +You can also create multi-page documentation, by creating several Markdown files: ```no-highlight @@ -116,47 +65,193 @@ nested URLs, like so: /license/ ``` -## Linking documents +### Configure Pages and Navigation + +The [pages configuration](configuration.md#pages) in your `mkdocs.yml` defines +which pages are built by MkDocs and how they appear in the documentation +navigation. If not provided, the pages configuration will be automatically +created by discovering all the Markdown files in the [documentation +directory](configuration.md#docs_dir). An automatically created pages +configuration will always be sorted alphanumerically by file name. You will need +to manually define your pages configuration if you would like your pages sorted +differently. + +A simple pages configuration looks like this: + +```no-highlight +pages: +- 'index.md' +- 'about.md' +``` + +With this example we will build two pages at the top level and they will +automatically have their titles inferred from the filename. Assuming `docs_dir` +has the default value, `docs`, the source files for this documentation would be +`docs/index.md` and `docs/about.md`. To provide a custom name for these pages, +they can be added before the filename. + +```no-highlight +pages: +- Home: 'index.md' +- About: 'about.md' +``` + +Subsections can be created by listing related pages together under a section +title. For example: + +```no-highlight +pages: +- Home: 'index.md' +- User Guide: + - 'Writing your docs': 'user-guide/writing-your-docs.md' + - 'Styling your docs': 'user-guide/styling-your-docs.md' +- About: + - 'License': 'about/license.md' + - 'Release Notes': 'about/release-notes.md' +``` + +With the above configuration we have three top level sections: Home, User Guide +and About. Then under User Guide we have two pages, Writing your docs and +Styling your docs. Under the About section we also have two pages, License and +Release Notes. + +Note that a section cannot have a page assigned to it. Sections are only +containers for child pages and sub-sections. You may nest sections as deeply as +you like. However, be careful that you don't make it too difficult for your +users to navigate through the site navigation by over-complicating the nesting. +While sections may mirror your directly structure, they do not have to. + +## Writing with Markdown + +MkDocs pages must be authored in [Markdown][md], a lightweight markup language +which results in easy-to-read, easy-to-write plain text documents that can be +converted to valid HTML documents in a predictable manner. + +MkDocs uses the [Python-Markdown] library to render Markdown documents to HTML. +Python-Markdown is almost completely compliant with the [reference +implementation][md], although there are a few very minor [differences]. + +In addition to the base Markdown [syntax] which is common across all Markdown +implementations, MkDocs includes support for extending the Markdown syntax with +Python-Markdown [extensions]. See the MkDocs' [markdown_extensions] +configuration setting for details on how to enable extensions. + +MkDocs includes some extensions by default, which are highlighted below. + +[Python-Markdown]: https://python-markdown.github.io/ +[md]: http://daringfireball.net/projects/markdown/ +[differences]: https://python-markdown.github.io/#differences +[syntax]: https://daringfireball.net/projects/markdown/syntax +[extensions]: https://python-markdown.github.io/extensions/ +[markdown_extensions]: configuration.md#markdown_extensions + +### Internal links MkDocs allows you to interlink your documentation by using regular Markdown -hyperlinks. +[links]. However, there are a few additional benefits to formatting those links +specifically for MkDocs as outlines below. -### Internal hyperlinks +[links]: https://daringfireball.net/projects/markdown/syntax#link + +#### Linking to pages When linking between pages in the documentation you can simply use the regular -Markdown hyperlinking syntax, including the relative path to the Markdown +Markdown [linking][links] syntax, including the *relative path* to the Markdown document you wish to link to. - Please see the [project license](license.md) for further details. +```no-highlight +Please see the [project license](license.md) for further details. +``` -When the MkDocs build runs, these hyperlinks will automatically be transformed -into a hyperlink to the appropriate HTML page. - -When working on your documentation you should be able to open the linked -Markdown document in a new editor window simply by clicking on the link. +When the MkDocs build runs, these Markdown links will automatically be +transformed into an HTML hyperlink to the appropriate HTML page. If the target documentation file is in another directory you'll need to make -sure to include any relative directory path in the hyperlink. +sure to include any relative directory path in the link. - Please see the [project license](../about/license.md) for further details. +```no-highlight +Please see the [project license](../about/license.md) for further details. +``` -You can also link to a section within a target documentation page by using an -anchor link. The generated HTML will correctly transform the path portion of the -hyperlink, and leave the anchor portion intact. +The [toc] extension is used by MkDocs to generate an ID for every header in your +Markdown documents. You can use that ID to link to a section within a target +document by using an anchor link. The generated HTML will correctly transform +the path portion of the link, and leave the anchor portion intact. - Please see the [project license](about.md#license) for further details. +```no-highlight +Please see the [project license](about.md#license) for further details. +``` -## Images and media +Note that IDs are created from the text of a header. All text is converted to +lowercase and any disallowed characters, including white-space, are converted to +dashes. Consecutive dashes are then reduced to a single dash. + +There are a few configuration settings provided by the toc extension which you +can set in your `mkdocs.yml` configuration file to alter the default behavior: + +`permalink`: + +: Generate permanent links at the end of each header. Default: `False`. + + When set to True the paragraph symbol (¶ or `¶`) is used as the + link text. When set to a string, the provided string is used as the link + text. For example, to use the hash symbol (`#`) instead, do: + + markdown_extensions: + - toc: + permalink: "#" + +`baselevel`: + +: Base level for headers. Default: `1`. + + This setting allows the header levels to be automatically adjusted to fit + within the hierarchy of your HTML templates. For example, if the Markdown + text for a page should not contain any headers higher than level 2 (`