文書を書く¶
Guidedog は reStructuredText(.rst)と MyST Markdown(.md)の両方に対応しています。どちらも同じ文書ツリーに解析され、HTML サイトと PDF の本はそのツリーから作られます。
ソース形式の選択¶
ドメイン、複雑な表、拡張可能なディレクティブをすべて使いたい場合は reStructuredText を使います。Markdown の構文を好みつつ、Sphinx 形式のディレクティブとロールも使いたい場合は MyST Markdown を使います。
ドキュメントプロジェクトでは、Markdown の文書は MyST として解析されます。guidedog convert による単一文書の変換では、Markdown をプレーンな CommonMark 0.31.2 として読みます。MyST のディレクティブ、ロール、設定はプロジェクトのための機能です。
見出しと構造¶
文書のタイトルはページを表し、セクションとサブセクションで本文を区切ります。reStructuredText では、見出しに下線の装飾を使います(同じ上線を付けることもできます)。下線は見出しの文字列以上の長さが必要です。
推奨する見出しの記号:
Document Title
==============
Section Heading
---------------
Subsection
~~~~~~~~~~
Sub-subsection
^^^^^^^^^^^^^^
Paragraph Heading
"""""""""""""""""
見出しの階層はプロジェクト全体でそろえます。MyST Markdown では、標準のハッシュ記号(#、##、###)を使います。
文字装飾とインライン記法¶
インラインのマークアップは装飾ではなく、意味を表すために使います。
| 書式 | reStructuredText | MyST Markdown |
|---|---|---|
| 太字 | **strong text** |
**strong text** |
| 強調・斜体 | *emphasized text* |
*emphasized text* |
インラインコード |
``inline code`` |
`inline code` |
| 下付き文字 | :sub:`text` |
{sub}`text` |
| 上付き文字 | :sup:`text` |
{sup}`text` |
アスタリスクやバッククォートを文字としてそのまま書くには、\*not italic\* のようにバックスラッシュでエスケープします。
リスト¶
Guidedog は四種類のリストに対応します。
箇条書き¶
* First item
* Second item with multiple lines
of continuing explanation.
* Third item
番号付きリスト¶
1. Numbered item
2. Second item
#. Automatically numbered item
#. Next auto-numbered item
定義リスト¶
定義リストは用語と説明を組にします。用語は一行に書き、そのすぐ後に字下げした定義を続けます。
Workspace
The reusable conversion context. It keeps its buffers between documents.
Project
A loaded configuration with its source folder, templates, and caches.
フィールドリスト¶
フィールドリストは構造化したメタデータや引数の説明に使います。
:Authors: Jane Doe, John Smith
:Version: 1.2
:Status: Active
文書のタイトルより前にフィールドリストがある場合、Guidedog は認識可能な公開メタデータフィールドをページのメタデータレコードに読み込み、レンダリングされる本文からは取り除きます。対象となるフィールドは :date:、:updated:、:publish-at:、:expires-at:、:draft:、:authors:、:category:、:tags:、:series:、:summary:、:template:、:pdf: です。MyST Markdown の文書では、先頭の YAML フロントマターで同じフィールドを指定します。タイトルより後ろにあるフィールドリストは通常の本文として扱われます。公開ライフサイクルの全体については 静的ウェブサイトと記事 を参照してください。
コードブロック¶
code-block ディレクティブ(または sourcecode)は、構文を強調表示したコードを表示します。Guidedog は Rust や Odin を含む 35 のプログラミング言語を、Pygments の名前とスタイルで強調表示します。Python のランタイムは不要です。
.. code-block:: python
:linenos:
:caption: Server entry point
:emphasize-lines: 2, 4-5
def main():
app = create_app()
app.run(host="0.0.0.0", port=8080)
コードブロックのオプション:
:linenos:: コードの横に行番号を表示します。:caption: Title: コードの上下にキャプションを付けます。:emphasize-lines: 1, 3-5: 指定した行を強調します。:name: label: コードに参照用のラベルを付けます。
ファイルからソースコードを取り込むには literalinclude を使います。
.. literalinclude:: ../src/server.py
:language: python
:lines: 1-25
:linenos:
注記ブロック¶
注記ブロックは注意事項、警告、補足を目立たせます。
.. note::
Helpful background context or implementation detail.
.. tip::
Suggested best practices or workflow shortcuts.
.. important::
Essential requirements that must not be overlooked.
.. warning::
Conditions that could lead to unexpected behavior or lost work.
.. caution::
Potential pitfalls or sensitive operational steps.
.. seealso::
References to related chapters, specifications, or external guides.
danger、error、hint、attention も使えます。独自のタイトルには admonition を使います。
.. admonition:: Design Rationale
Explains why a particular architecture was chosen.
表¶
Guidedog はシンプルテーブル、グリッドテーブル、ディレクティブによる表に対応します。
シンプルテーブル¶
シンプルテーブルは横線で列の範囲を示します。
===== ===== =======
A B A and B
===== ===== =======
False False False
True False False
True True True
===== ===== =======
グリッドテーブル¶
グリッドテーブルは複数行のセルや、行・列にまたがるセルを扱えます。
+------------------------+------------+----------+
| Header row, column 1 | Column 2 | Column 3 |
+========================+============+==========+
| Cell with multiple | Second | Third |
| paragraphs of text. | column | column |
+------------------------+------------+----------+
リストテーブル¶
list-table ディレクティブは、入れ子の箇条書きから表を作ります。幅の広い表でも、ソース上で読みやすく管理しやすいままです。
.. list-table:: Project configurations
:widths: 25 25 50
:header-rows: 1
* - Target
- Builder
- Description
* - Website
- ``html``
- Static HTML documentation site
* - Book
- ``pdf``
- Typeset PDF book powered by Typst
CSV テーブル¶
csv-table はカンマ区切りのデータから表を作ります。
.. csv-table:: Comparative metrics
:header: "Name", "Time (ms)", "Memory (MB)"
:widths: 40, 30, 30
"Cold build", 42, 12
"Incremental", 3, 4
画像と図¶
イラスト、スクリーンショット、作成済みの図は image と figure で組み込みます。また、Graphviz や Typst の図、および LilyPond の楽譜をマークアップ内で直接記述し、HTML と PDF 用のアセットを自動生成することもできます。詳しくは Graphviz と Typst による図 と 楽譜の記法 を参照してください。
既存の画像の場合:
.. image:: /assets/architecture.png
:width: 600px
:align: center
:alt: System architecture diagram
.. figure:: /assets/flow.png
:scale: 80%
:align: center
:alt: Execution flowchart
Data flows sequentially through reader, resolver, and renderer.
figure は画像にキャプションを付け、参照用のターゲットも指定できます。
目次ツリーで構成する¶
toctree は文書の階層、ナビゲーション、HTML と PDF の読み順を定義します。
.. toctree::
:maxdepth: 2
:caption: User Guide
:numbered:
installation
quickstart
configuration
toctree の主なオプション:
:maxdepth: N: 目次に含める見出しの深さ。:caption: Title: ナビゲーション項目の上に表示する分類名。:numbered:: 章と見出しに番号を付けます。:titlesonly:: 文書のタイトルだけを並べ、内部の見出しは省きます。:hidden:: 本文内にリストを表示せず、読み順だけを記録します。:glob::tutorials/*のようなワイルドカードで文書を選べます。
postlist による日付付き記事の一覧¶
:date: メタデータを持つ記事、リリースノート、研究ログに対して、postlist ディレクティブは条件に一致する公開済みページを新しい順の一覧として出力します。
.. postlist:: 5
:path: posts/*
:category: systems
:tags: rust, incremental
:excerpts:
postlist のオプション:
- 引数
N: 表示する記事の最大件数。0 または省略時は一致するすべての記事を含めます。 :path: GLOB: glob パターンに一致する文書名の項目に絞り込みます。:category: NAME、:tags: TAG, ...、:author: NAME、:series: NAME、:year: YYYY: 公開メタデータで項目を絞り込みます。:sort: dateまたは:sort: -date: 公開日時の古い順または新しい順に並べます(同時刻の場合は文書名順)。:style: listまたは:style: cards: 一覧の CSS クラスを選択します。:excerpts:: 各項目の.. more::より前にある書式付き導入部をレンダリングします。境界がない場合はプレーンテキストの:summary:を使用します。
コレクション、フィード、予約公開については 静的ウェブサイトと記事 を参照してください。
相互参照とリンク¶
明示的なターゲットを使えば、文書ファイルの名前を変えてもリンクは壊れません。
ラベルと :ref:¶
見出し、表、図の直前にターゲットのラベルを置きます。
.. _storage-model:
Storage model
-------------
Every conversion runs within explicit limits.
プロジェクト内のどの文書からも、このターゲットを参照できます。
See :ref:`storage-model` for details.
See :ref:`custom link text <storage-model>`.
:doc: による文書参照¶
別の文書へは、拡張子を省いたパスでリンクします。
Read the :doc:`configuration guide <../reference/configuration>` for details.
:term: による用語参照¶
用語は glossary ディレクティブで定義します。
.. glossary::
Workspace
A reusable context whose buffers keep their capacity between conversions.
Pass
An in-memory transformation step operating on the document AST.
用語集の用語へは :term: ロールでリンクします。
Conversion runs within a reusable :term:`workspace`.
:download: によるファイル配布¶
次のように書くと、ファイルを出力先のダウンロード用ディレクトリにコピーし、そこへのリンクを作ります。
Download the :download:`starter template <files/starter.toml>`.
外部リンクとマウント間リンク¶
外部の Web アドレスへは次のようにリンクします。
Visit `Typst <https://typst.app>`_ for typography details.
[[site.mounts]] で組み立てたマルチプロジェクトのウェブサイトでは、mount://<name>/<path> を使ってマウント名でサブプロジェクトへリンクすることもできます。
Read the `User Manual <mount://manual/index.html>`_ or `GDS 0013 <mount://discussions/records/0013-static-site-generation.html>`_.
マウント名は [[site.mounts]] と一致し、パスは現在の出力ファイルを指している必要があります。
置換と取り込み¶
再利用する語句、記号、画像を定義します。
.. |version| replace:: 1.0.0
.. |brand| replace:: **Field Notes**
Welcome to |brand| version |version|.
reStructuredText の内容を複数のファイルで再利用するには、次のようにします。
.. include:: ../shared/warnings.rst
MyST Markdown を書く¶
MyST Markdown では、フェンス付きブロックで同じディレクティブとロールを使えます。
# Project overview
Here is a paragraph with **bold text**, *italic emphasis*, and `inline code`.
```{note}
This note is rendered identically to a reStructuredText note directive.
```
```{code-block} python
:caption: Example function
:linenos:
def add(a, b):
return a + b
```
```{toctree}
:maxdepth: 2
:caption: Navigation
first-chapter
second-chapter
```
See {ref}`storage-model` or consult the {doc}`../reference/configuration`.