Markdownによる記述

Sphinxはデフォルトで、reStructuredText (reST)というマークアップ言語で記述しますが、Markdownやその拡張であるMySTでも記述できます。

Markdown(MyST)を使うには、Sphinx拡張の MyST-Parser をインストールします。

MyST-Parserのインストール
$ python -m pip install myst-parser

次に conf.pyextensions のリストに 'myst_parser' を追加します。

conf.py
 1# Configuration file for the Sphinx documentation builder.
 2#
 3# For the full list of built-in configuration values, see the documentation:
 4# https://www.sphinx-doc.org/en/master/usage/configuration.html
 5
 6# -- Project information -----------------------------------------------------
 7# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
 8
 9project = 'sample'
10copyright = '2024, your_name'
11author = 'your_name'
12
13# -- General configuration ---------------------------------------------------
14# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
15
16extensions = ['myst_parser']
17
18templates_path = ['_templates']
19exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
20
21
22
23# -- Options for HTML output -------------------------------------------------
24# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
25
26html_theme = 'alabaster'
27html_static_path = ['_static']

Markdownでテキストファイルを記述します、ここでは hello.md というファイルを作成します。

hello.md
# はじめてのSphinx

[Markdown](https://daringfireball.net/projects/markdown/)記法にしたがって記述できます。

## リスト

順序なしリスト

- グー
- チョキ
- パー

順序付きリスト

1. ウォード
2. トラウト
3. 大谷

## ブロッククォート

> 引用
>> ネストされた引用

index.rsthello.md をtoctreeに追加します。toctreeとは複数の文書を構造化するために使われます。toctreeでは、章-節などの複雑な構造をもつ文書を作成できますが、ここではtoctreeに記述したファイルの順番に文書が出力されると覚えておいてください。toctreeにファイルを追加するときに、ファイルの拡張子は記述しません。

index.rst
 1.. sample documentation master file, created by
 2   sphinx-quickstart on Sat Jan 13 14:30:31 2024.
 3   You can adapt this file completely to your liking, but it should at least
 4   contain the root `toctree` directive.
 5
 6Welcome to sample's documentation!
 7==================================
 8
 9.. toctree::
10   :maxdepth: 2
11   :caption: Contents:
12
13   hello
14
15Indices and tables
16==================
17
18* :ref:`genindex`
19* :ref:`modindex`
20* :ref:`search`

HTMLにビルドします、HTMLに hello.md の内容が追加されます。

HTMLへビルド
$ make html