Part 1
요약·해설
Heading underline, inline markup, list와 responsive column, grid/list table, file role와 cross-reference, non-ASCII substitution, Pygments code block, image·indent·tab, 19개 zephyr-app-commands option을 다룹니다.
reST · Sphinx
Lists · Tables · Code
Roles · App Commands
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
05BE4A310CE2E893D6F377F747C660D955B1954BCFC1C66AA10176D1109DDA65
.. _doc_guidelines:
Documentation Guidelines
########################
.. highlight:: rst
.. note::
For instructions on building the documentation, see :ref:`zephyr_doc`.
Zephyr Project content is written using the `reStructuredText`_ markup
language (.rst file extension) with Sphinx extensions, and processed
using Sphinx to create a formatted standalone website. Developers can
view this content either in its raw form as .rst markup files, or (with
Sphinx installed) they can :ref:`build the documentation <zephyr_doc>` locally
to generate the documentation in HTML or PDF format. The HTML content can
then be viewed using a web browser. This same .rst content is served by the
`Zephyr documentation`_ website.
You can read details about `reStructuredText`_
and about `Sphinx extensions`_ from their respective websites.
.. _Sphinx extensions: http://www.sphinx-doc.org/en/stable/contents.html
.. _reStructuredText: http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html
.. _Sphinx Inline Markup: http://sphinx-doc.org/markup/inline.html#inline-markup
.. _Zephyr documentation: https://docs.zephyrproject.org
This document provides a quick reference for commonly used reST and
Sphinx-defined directives and roles used to create the documentation
you're reading.
Headings
********
While reST allows use of both and overline and matching underline to
indicate a heading, we only use an underline indicator for headings.
* Document title (h1) use "#" for the underline character
* First section heading level (h2) use "*"
* Second section heading level (h3) use "="
* Third section heading level (h4) use "-"
The heading underline must be at least as long as the title it's under.
For example::
This is a title heading
#######################
some content goes here
First section heading
*********************
Content Highlighting
********************
Some common reST inline markup samples:
* one asterisk: ``*text*`` for emphasis (*italics*),
* two asterisks: ``**text**`` for strong emphasis (**boldface**), and
* two backquotes: ````text```` for ``inline code`` samples.
If asterisks or backquotes appear in running text and could be confused with
inline markup delimiters, you can eliminate the confusion by adding a
backslash (``\``) before it.
Lists
*****
For bullet lists, place an asterisk (``*``) or hyphen (``-``) at
the start of a paragraph and indent continuation lines with two
spaces.
The first item in a list (or sublist) must have a blank line before it
and should be indented at the same level as the preceding paragraph
(and not indented itself).
For numbered lists
start with a 1. or a. for example, and continue with autonumbering by
using a ``#`` sign. Indent continuation lines with three spaces::
* This is a bulleted list.
* It has two items, the second
item and has more than one line of reST text. Additional lines
are indented to the first character of the
text of the bullet list.
1. This is a new numbered list. If the wasn't a blank line before it,
it would be a continuation of the previous list (or paragraph).
#. It has two items too.
a. This is a numbered list using alphabetic list headings
#. It has three items (and uses autonumbering for the rest of the list)
#. Here's the third item
#. This is an autonumbered list (default is to use numbers starting
with 1).
#. This is a second-level list under the first item (also
autonumbered). Notice the indenting.
#. And a second item in the nested list.
#. And a second item back in the containing list. No blank line
needed, but it wouldn't hurt for readability.
Definition lists (with a term and its definition) are a convenient way
to document a word or phrase with an explanation. For example this reST
content::
The Makefile has targets that include:
html
Build the HTML output for the project
clean
Remove all generated output, restoring the folders to a
clean state.
Would be rendered as:
The Makefile has targets that include:
html
Build the HTML output for the project
clean
Remove all generated output, restoring the folders to a
clean state.
Multi-column lists
******************
If you have a long bullet list of items, where each item is short, you
can indicate the list items should be rendered in multiple columns with
a special ``.. rst-class:: rst-columns`` directive. The directive will
apply to the next non-comment element (e.g., paragraph), or to content
indented under the directive. For example, this unordered list::
.. rst-class:: rst-columns
* A list of
* short items
* that should be
* displayed
* horizontally
* so it doesn't
* use up so much
* space on
* the page
would be rendered as:
.. rst-class:: rst-columns
* A list of
* short items
* that should be
* displayed
* horizontally
* so it doesn't
* use up so much
* space on
* the page
A maximum of three columns will be displayed, and change based on the
available width of the display window, reducing to one column on narrow
(phone) screens if necessary. We've deprecated use of the ``hlist``
directive because it misbehaves on smaller screens.
Tables
******
There are a few ways to create tables, each with their limitations or
quirks. `Grid tables
<http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#grid-tables>`_
offer the most capability for defining merged rows and columns, but are
hard to maintain::
+------------------------+------------+----------+----------+
| Header row, column 1 | Header 2 | Header 3 | Header 4 |
| (header rows optional) | | | |
+========================+============+==========+==========+
| body row 1, column 1 | column 2 | column 3 | column 4 |
+------------------------+------------+----------+----------+
| body row 2 | ... | ... | you can |
+------------------------+------------+----------+ easily +
| body row 3 with a two column span | ... | span |
+------------------------+------------+----------+ rows +
| body row 4 | ... | ... | too |
+------------------------+------------+----------+----------+
This example would render as:
+------------------------+------------+----------+----------+
| Header row, column 1 | Header 2 | Header 3 | Header 4 |
| (header rows optional) | | | |
+========================+============+==========+==========+
| body row 1, column 1 | column 2 | column 3 | column 4 |
+------------------------+------------+----------+----------+
| body row 2 | ... | ... | you can |
+------------------------+------------+----------+ easily +
| body row 3 with a two column span | ... | span |
+------------------------+------------+----------+ rows +
| body row 4 | ... | ... | too |
+------------------------+------------+----------+----------+
`List tables
<http://docutils.sourceforge.net/docs/ref/rst/directives.html#list-table>`_
are much easier to maintain, but don't support row or column spans::
.. list-table:: Table title
:widths: 15 20 40
:header-rows: 1
* - Heading 1
- Heading 2
- Heading 3
* - body row 1, column 1
- body row 1, column 2
- body row 1, column 3
* - body row 2, column 1
- body row 2, column 2
- body row 2, column 3
This example would render as:
.. list-table:: Table title
:widths: 15 20 40
:header-rows: 1
* - Heading 1
- Heading 2
- Heading 3
* - body row 1, column 1
- body row 1, column 2
- body row 1, column 3
* - body row 2, column 1
- body row 2, column 2
- body row 2, column 3
The ``:widths:`` parameter lets you define relative column widths. The
default is equal column widths. If you have a three-column table and you
want the first column to be half as wide as the other two equal-width
columns, you can specify ``:widths: 1 2 2``. If you'd like the browser
to set the column widths automatically based on the column contents, you
can use ``:widths: auto``.
File names and Commands
***********************
Sphinx extends reST by supporting additional inline markup elements (called
"roles") used to tag text with special
meanings and allow style output formatting. (You can refer to the `Sphinx Inline Markup`_
documentation for the full list).
For example, there are roles for marking :file:`filenames`
(``:file:`name```) and command names such as :command:`make`
(``:command:`make```). You can also use the \`\`inline code\`\`
markup (double backticks) to indicate a ``filename``.
For references to files that are in the Zephyr GitHub tree, a special
role can be used that creates a hyperlink to that file. For example a
reference to the reST file used to create this document can be generated
using ``:zephyr_file:`doc/contribute/documentation/guidelines.rst``` that will
show up as :zephyr_file:`doc/contribute/documentation/guidelines.rst`, a link to
the "blob" file in the github repo. There's also a
``:zephyr_raw:`doc/contribute/documentation/guidelines.rst``` role that will
link to the "raw" content,
:zephyr_raw:`doc/contribute/documentation/guidelines.rst`. (You can click on
these links to see the difference.)
.. _internal-linking:
Internal Cross-Reference Linking
********************************
Traditional ReST links are only supported within the current file using the
notation::
Refer to the `internal-linking`_ page
which renders as,
Refer to the `internal-linking`_ page
Note the use of a trailing
underscore to indicate an outbound link. In this example, the label was
added immediately before a heading, so the text that's displayed is the
heading text itself. You can change the text that's displayed as the
link writing this as::
Refer to the `show this text instead <internal-linking_>`_ page
which renders as,
Refer to the `show this text instead <internal-linking_>`_ page
External Cross-Reference Linking
********************************
With Sphinx's help, we can create
link-references to any tagged text within the Zephyr Project documentation.
Target locations in a document are defined with a label directive::
.. _my label name:
Heading
=======
Note the leading underscore indicating an inbound link.
The content immediately following
this label must be a heading, and is the target for a ``:ref:`my label name```
reference from anywhere within the Zephyr documentation.
The heading text is shown when referencing this label.
You can also change the text that's displayed for this link, such as::
:ref:`some other text <my label name>`
To enable easy cross-page linking within the site, each file should have
a reference label before its title so it can
be referenced from another file. These reference labels must be unique
across the whole site, so generic names such as "samples" should be
avoided. For example the top of this document's .rst file is::
.. _doc_guidelines:
Documentation Guidelines for the Zephyr Project
###############################################
Other .rst documents can link to this document using the ``:ref:`doc_guidelines``` tag and
it will show up as :ref:`doc_guidelines`. This type of internal cross reference works across
multiple files, and the link text is obtained from the document source so if the title changes,
the link text will update as well.
You can also define links to any URL and then reference it in your document.
For example, with this label definition in the document::
.. _Zephyr Wikipedia Page:
https://en.wikipedia.org/wiki/Zephyr_(operating_system)
you can reference it with::
Read the `Zephyr Wikipedia Page`_ for more information about the
project.
\`any\` links
*************
Within the Zephyr project, we've defined the default role to be "any",
meaning if you just write a phrase in back-ticks, e.g.,
```doc_guidelines```, Sphinx will search through all domains looking for
something called doc_guidelines to link to. In this case it will find
the label at the top of this document, and link to `doc_guidelines`.
This can be useful for linking to doxygen-generated links for function
names and such, but will cause a warning such as::
WARNING: 'any' reference target not found: doc_giudelines
if you misspelled ```doc_guidelines``` as ```doc_giudelines```.
Non-ASCII Characters
********************
You can insert non-ASCII characters such as a Trademark symbol (|trade|),
by using the notation ``|trade|``.
Available replacement names are defined in an include file used during the Sphinx processing
of the reST files. The names of these replacement characters are the same as used in HTML
entities used to insert characters in HTML, e.g., \™ and are defined in the
file ``sphinx_build/substitutions.txt`` as listed here:
.. literalinclude:: ../../../../substitutions.txt
:language: rst
We've kept the substitutions list small but others can be added as
needed by submitting a change to the ``substitutions.txt`` file.
Code and Command Examples
*************************
Use the reST ``code-block`` directive to create a highlighted block of
fixed-width text, typically used for showing formatted code or console
commands and output. Smart syntax highlighting is also supported (using the
Pygments package). You can also directly specify the highlighting language.
For example::
.. code-block:: c
struct k_object {
char *name;
uint8_t perms[CONFIG_MAX_THREAD_BYTES];
uint8_t type;
uint8_t flags;
uint32_t data;
} __packed;
Note the blank line between the ``code-block`` directive and the first
line of the code-block body, and the body content is indented three
spaces (to the first non-white space of the directive name).
This would be rendered as:
.. code-block:: c
struct k_object {
char *name;
uint8_t perms[CONFIG_MAX_THREAD_BYTES];
uint8_t type;
uint8_t flags;
uint32_t data;
} __packed;
Other languages are of course supported (see `languages supported by Pygments`_), and in particular,
you are encouraged to make use of the following when appropriate:
.. _`languages supported by Pygments`: http://pygments.org/languages/
* ``c`` for C code
* ``cpp`` for C++ code
* ``python`` for Python code
* ``console`` for console output, i.e. interactive shell sessions where commands are prefixed by a
prompt (ex. ``$`` for Linux, or ``uart:~$`` for Zephyr's shell), and where the output is also
shown. The commands will be highlighted, and the output will not. What's more, copying code block
using the "copy" button will automatically copy just the commands, excluding the prompt and the
outputs of the commands.
* ``shell`` or ``bash`` for shell commands. Both languages get highlighted the same but you may use
``bash`` for conveying that the commands are bash-specific, and ``shell`` for generic shell
commands.
.. note::
Do not use ``bash`` or ``shell`` if your code block includes a prompt, use ``console`` instead.
Reciprocally, do not use ``console`` if your code block does not include a prompt and is not
showcasing an interactive session with command(s) and their output.
.. list-table:: When to use ``bash``/``shell`` vs. ``console``
:class: wrap-normal
:header-rows: 1
:widths: 20,40,40
* - Use case
- ``code-block`` snippet
- Expected output
* - One or several commands, no output
- .. code-block:: rst
.. code-block:: shell
echo "Hello World!"
- .. code-block:: shell
echo "Hello World!"
* - An interactive shell session with command(s) and their output
- .. code-block:: rst
.. code-block:: console
$ echo "Hello World!"
Hello World!
- .. code-block:: console
$ echo "Hello World!"
Hello World!
* - An interactive Zephyr shell session, with commands and their outputs
- .. code-block:: rst
.. code-block:: console
uart:~$ version
Zephyr version 3.5.99
uart:~$ kernel uptime
Uptime: 20970 ms
- .. code-block:: console
uart:~$ version
Zephyr version 3.5.99
uart:~$ kernel uptime
Uptime: 20970 ms
* ``bat`` for Windows batch files
* ``cfg`` for config files with "KEY=value" entries (ex. Kconfig ``.conf`` files)
* ``cmake`` for CMake
* ``devicetree`` for Devicetree
* ``kconfig`` for Kconfig
* ``yaml`` for YAML
* ``rst`` for reStructuredText
When no language is specified, the language is set to ``none`` and the code block is not
highlighted. You may also use ``none`` explicitly to achieve the same result; for example::
.. code-block:: none
This would be a block of text styled with a background
and box, but with no syntax highlighting.
Would display as:
.. code-block:: none
This would be a block of text styled with a background
and box, but with no syntax highlighting.
There's a shorthand for writing code blocks too: end the introductory paragraph with a double colon
(``::``) and indent the code block content that follows it by three spaces. On output, only one
colon will be shown. The code block will have no highlighting (i.e. ``none``). You may however use
the ``.. highlight::`` directive to customize the default language used in your document (see for
example how this is done at the beginning of this very document).
Images
******
Images are included in documentation by using an image directive::
.. image:: ../../../../images/doc-gen-flow.png
:align: center
:alt: alt text for the image
or if you'd like to add an image caption, use::
.. figure:: ../../../../images/doc-gen-flow.png
:alt: image description
Caption for the figure
The file name specified is relative to the document source file,
and we recommend putting images into an ``images`` folder where the document
source is found. The usual image formats handled by a web browser are
supported: JPEG, PNG, GIF, and SVG. Keep the image size only as large
as needed, generally at least 500 px wide but no more than 1000 px, and
no more than 250 KB unless a particularly large image is needed for
clarity.
Tabs, spaces, and indenting
***************************
Indenting is significant in reST file content, and using spaces is
preferred. Extra indenting can (unintentionally) change the way content
is rendered too. For lists and directives, indent the content text to
the first non-white space in the preceding line. For example::
* List item that spans multiple lines of text
showing where to indent the continuation line.
1. And for numbered list items, the continuation
line should align with the text of the line above.
.. code-block::
The text within a directive block should align with the
first character of the directive name.
Refer to the Zephyr :ref:`coding_style` for additional requirements.
zephyr-app-commands Directive
*****************************
.. include:: ../../../../_extensions/zephyr/application.py
:start-line: 10
:start-after: '''
:end-before: '''
For example, the ``.. zephyr-app-commands`` listed above would
render like this in the generated HTML output:
.. zephyr-app-commands::
:zephyr-app: samples/hello_world
:board: qemu_x86
:goals: build
Alternative Tabbed Content
**************************
As introduced in the :ref:`getting_started`, you can provide alternative
content to the reader via a tabbed interface. When the reader clicks on
a tab, the content for that tab is displayed, for example::
.. tabs::
.. tab:: Apples
Apples are green, or sometimes red.
.. tab:: Pears
Pears are green.
.. tab:: Oranges
Oranges are orange.
will display as:
.. tabs::
.. tab:: Apples
Apples are green, or sometimes red.
.. tab:: Pears
Pears are green.
.. tab:: Oranges
Oranges are orange.
Tabs can also be grouped, so that changing the current tab in one area
changes all tabs with the same name throughout the page. For example:
.. tabs::
.. group-tab:: Linux
Linux Line 1
.. group-tab:: macOS
macOS Line 1
.. group-tab:: Windows
Windows Line 1
.. tabs::
.. group-tab:: Linux
Linux Line 2
.. group-tab:: macOS
macOS Line 2
.. group-tab:: Windows
Windows Line 2
In this latter case, we're using ``.. group-tab::`` instead of simply
``.. tab::``. Under the hood, we're using the `sphinx-tabs
<https://github.com/djungelorm/sphinx-tabs>`_ extension that's included
in the Zephyr setup. Within a tab, you can have most any content *other
than a heading* (code-blocks, ordered and unordered lists, pictures,
paragraphs, and such). You can read more about sphinx-tabs from the
link above.
Part 3
한국어 전문 번역
Documentation Guidelines
Zephyr Project content는 Sphinx extension을 포함한 reStructuredText markup language(.rst 확장자)로 작성하고 Sphinx로 처리해 standalone website를 만듭니다. Raw .rst file을 직접 보거나 Sphinx로 local HTML·PDF를 생성할 수 있으며 같은 content가 Zephyr documentation website에 제공됩니다.
Sphinx extensions도 공식 website에서 자세히 확인할 수 있습니다.
이 문서는 현재 읽고 있는 문서를 만드는 데 자주 쓰는 reST와 Sphinx directive·role의 빠른 참고서입니다.
Heading
reST는 heading에 overline과 같은 길이의 underline을 함께 쓸 수 있지만 Zephyr 문서에서는 underline만 사용합니다.
- Document title(h1)은 underline에
#을 사용합니다. - 첫 section heading(h2)은
*을 사용합니다. - 둘째 section heading(h3)은
=을 사용합니다. - 셋째 section heading(h4)은
-을 사용합니다.
Heading underline은 위 title만큼 길어야 합니다.
This is a title heading
#######################
some content goes here
First section heading
*********************Content 강조
자주 쓰는 reST inline markup은 다음과 같습니다.
- Asterisk 하나
*text*는 emphasis, 즉 italic입니다. - Asterisk 두 개
**text**는 strong emphasis, 즉 bold입니다. - Backquote 두 개
``text``는 inline code sample입니다.
일반 문장 안의 asterisk나 backquote가 inline markup delimiter와 혼동될 수 있으면 앞에 backslash \를 붙입니다.
List
Bullet list는 paragraph 시작에 asterisk * 또는 hyphen -을 두고 이어지는 줄을 space 두 칸으로 indent합니다.
List 또는 sublist의 첫 항목 앞에는 빈 줄이 있어야 하며 앞 paragraph와 같은 level에서 시작해야 합니다.
Numbered list는 1. 또는 a.로 시작하고 나머지는 #으로 자동 번호를 붙일 수 있습니다. 이어지는 줄은 space 세 칸으로 indent합니다.
* This is a bulleted list.
* It has two items, the second
item and has more than one line of reST text. Additional lines
are indented to the first character of the
text of the bullet list.
1. This is a new numbered list. If the wasn't a blank line before it,
it would be a continuation of the previous list (or paragraph).
#. It has two items too.
a. This is a numbered list using alphabetic list headings
#. It has three items (and uses autonumbering for the rest of the list)
#. Here's the third item
#. This is an autonumbered list (default is to use numbers starting
with 1).
#. This is a second-level list under the first item (also
autonumbered). Notice the indenting.
#. And a second item in the nested list.
#. And a second item back in the containing list. No blank line
needed, but it wouldn't hurt for readability.Definition list는 term과 설명을 한 쌍으로 문서화할 때 편리합니다. 다음 source를 사용합니다.
The Makefile has targets that include:
html
Build the HTML output for the project
clean
Remove all generated output, restoring the folders to a
clean state.렌더링 결과:
The Makefile has targets that include:
htmlProject의 HTML output을 build합니다.
clean생성된 output을 모두 제거해 folder를 깨끗한 상태로 되돌립니다.
여러 column의 list
항목마다 짧은 긴 bullet list는 .. rst-class:: rst-columns directive로 여러 column에 표시할 수 있습니다. Directive는 다음 non-comment element 또는 아래에 indent한 content에 적용됩니다.
.. rst-class:: rst-columns
* A list of
* short items
* that should be
* displayed
* horizontally
* so it doesn't
* use up so much
* space on
* the page렌더링 결과:
- A list of
- short items
- that should be
- displayed
- horizontally
- so it doesn't
- use up so much
- space on
- the page
최대 세 column을 표시하고 window 폭에 따라 바뀝니다. 좁은 phone 화면에서는 필요하면 한 column으로 줄어듭니다. 작은 화면에서 잘못 동작하는 hlist directive는 deprecated되었습니다.
Table
Table을 만드는 방법은 여러 가지이며 각각 제약과 특성이 있습니다. Grid tables는 row·column 병합 기능이 가장 강력하지만 유지보수가 어렵습니다.
+------------------------+------------+----------+----------+
| Header row, column 1 | Header 2 | Header 3 | Header 4 |
| (header rows optional) | | | |
+========================+============+==========+==========+
| body row 1, column 1 | column 2 | column 3 | column 4 |
+------------------------+------------+----------+----------+
| body row 2 | ... | ... | you can |
+------------------------+------------+----------+ easily +
| body row 3 with a two column span | ... | span |
+------------------------+------------+----------+ rows +
| body row 4 | ... | ... | too |
+------------------------+------------+----------+----------+렌더링 결과:
| Header row, column 1 (header rows optional) | Header 2 | Header 3 | Header 4 |
|---|---|---|---|
| body row 1, column 1 | column 2 | column 3 | column 4 |
| body row 2 | ... | ... | you can easily span rows too |
| body row 3 with a two column span | ... | ||
| body row 4 | ... | ... | |
List tables는 유지보수가 훨씬 쉽지만 row나 column span을 지원하지 않습니다.
.. list-table:: Table title
:widths: 15 20 40
:header-rows: 1
* - Heading 1
- Heading 2
- Heading 3
* - body row 1, column 1
- body row 1, column 2
- body row 1, column 3
* - body row 2, column 1
- body row 2, column 2
- body row 2, column 3렌더링 결과:
| Heading 1 | Heading 2 | Heading 3 |
|---|---|---|
| body row 1, column 1 | body row 1, column 2 | body row 1, column 3 |
| body row 2, column 1 | body row 2, column 2 | body row 2, column 3 |
:widths: parameter로 상대 column 폭을 정의합니다. 기본값은 같은 폭입니다. 세 column에서 첫 column을 나머지 두 column의 절반으로 만들려면 :widths: 1 2 2를 사용합니다. Browser가 content에 맞춰 자동 결정하게 하려면 :widths: auto를 사용합니다.
File name과 command
Sphinx는 특별한 의미와 output style을 지정하는 role을 추가합니다. 전체 목록은 Sphinx Inline Markup을 참고하십시오.
:file:`name`은 filename, :command:`make`은 command name을 표시합니다. Double backtick inline code도 filename 표시에 사용할 수 있습니다.
Zephyr GitHub tree의 file에는 hyperlink를 만드는 전용 role을 사용합니다. :zephyr_file:`doc/contribute/documentation/guidelines.rst`은 GitHub blob file로, :zephyr_raw:`doc/contribute/documentation/guidelines.rst`은 raw content로 연결합니다.
File 내부 cross-reference link
전통적인 reST link는 현재 file 안에서만 다음 표기법으로 지원됩니다.
Refer to the `internal-linking`_ page뒤 underscore는 outbound link임을 뜻합니다. Label이 heading 바로 앞에 있으므로 표시 text는 heading text가 됩니다. 표시 text를 바꾸려면 다음과 같이 씁니다.
Refer to the `show this text instead <internal-linking_>`_ pageFile 사이 cross-reference link
Sphinx를 사용하면 Zephyr Project documentation 전체에서 label을 붙인 text로 link할 수 있습니다. Target은 label directive로 정의합니다.
.. _my label name:
Heading
=======앞 underscore는 inbound link를 뜻합니다. Label 바로 뒤 content는 heading이어야 하며 문서 어디서나 :ref:`my label name`으로 참조할 수 있습니다. 표시 text를 바꾸려면 다음과 같이 씁니다.
:ref:`some other text <my label name>`Site 안의 page 간 link를 쉽게 만들려면 각 file의 title 앞에 reference label을 둡니다. 전체 site에서 고유해야 하므로 samples 같은 일반 이름은 피합니다.
.. _doc_guidelines:
Documentation Guidelines for the Zephyr Project
###############################################:ref:`doc_guidelines`로 이 문서를 참조하면 source title이 link text가 됩니다. 여러 file을 가로질러 동작하며 title이 바뀌면 link text도 갱신됩니다.
임의 URL의 label을 정의하고 문서에서 참조할 수도 있습니다.
.. _Zephyr Wikipedia Page:
https://en.wikipedia.org/wiki/Zephyr_(operating_system)Read the `Zephyr Wikipedia Page`_ for more information about the
project.렌더링된 Zephyr Wikipedia Page link는 label에 지정한 URL로 이동합니다.
`any` link
Zephyr project는 default role을 any로 정의합니다. Backtick 안에 `doc_guidelines`처럼 쓰면 Sphinx가 모든 domain에서 그 이름의 대상을 찾아 link합니다. Doxygen이 생성한 function name 등에 편리하지만 철자가 틀리면 다음 warning이 발생합니다.
WARNING: 'any' reference target not found: doc_giudelinesNon-ASCII 문자
Trademark symbol 같은 non-ASCII 문자는 |trade| notation으로 삽입합니다. Replacement name은 Sphinx가 reST를 처리할 때 include하는 sphinx_build/substitutions.txt에 정의하며 HTML entity와 같은 이름을 사용합니다.
.. |br| raw:: html .. force a line break in HTML output (blank lines needed here)
<br />
.. |p| raw:: html .. force a blank line in HTML output (blank lines needed here)
<p></p>
.. These are replacement strings for non-ASCII characters used within the project
using the same name as the html entity names (e.g., ©) for that character
.. |copy| unicode:: U+000A9 .. COPYRIGHT SIGN
:ltrim:
.. |trade| unicode:: U+02122 .. TRADEMARK SIGN
:ltrim:
.. |reg| unicode:: U+000AE .. REGISTERED TRADEMARK SIGN
:ltrim:
.. |deg| unicode:: U+000B0 .. DEGREE SIGN
:ltrim:
.. |plusminus| unicode:: U+000B1 .. PLUS-MINUS SIGN
:rtrim:
.. |micro| unicode:: U+000B5 .. MICRO SIGN
:rtrim:
.. |sup2| unicode:: U+00B2 .. SUPERSCRIPT TWO
:ltrim:substitutions.txt 목록은 작게 유지하지만 필요하면 변경을 제출해 항목을 추가할 수 있습니다.
Code와 command example
reST code-block directive는 code, console command, output 같은 fixed-width text를 syntax highlighting해 표시합니다. Pygments를 사용하며 language를 직접 지정할 수 있습니다.
.. code-block:: c
struct k_object {
char *name;
uint8_t perms[CONFIG_MAX_THREAD_BYTES];
uint8_t type;
uint8_t flags;
uint32_t data;
} __packed;code-block directive와 첫 code line 사이에는 빈 줄이 있어야 하며 body는 directive name의 첫 non-whitespace character에 맞춰 space 세 칸으로 indent합니다. 렌더링 결과:
struct k_object {
char *name;
uint8_t perms[CONFIG_MAX_THREAD_BYTES];
uint8_t type;
uint8_t flags;
uint32_t data;
} __packed;Pygments 지원 language 가운데 다음 값을 상황에 맞게 사용하는 것이 좋습니다.
c는 C codecpp는 C++ codepython은 Python codeconsole은 prompt와 output을 포함한 interactive shell session. Copy button은 prompt와 output을 제외하고 command만 복사합니다.shell또는bash는 shell command. Bash 전용이면 bash, 일반 command면 shell을 사용합니다.bat는 Windows batch filecfg는KEY=value형식 config filecmake는 CMakedevicetree는 Devicetreekconfig는 Kconfigyaml은 YAMLrst는 reStructuredText
| 사용 사례 | code-block snippet | 예상 output |
|---|---|---|
| Output 없는 command 하나 이상 | | |
| Command와 output이 있는 interactive shell session | | |
| Command와 output이 있는 interactive Zephyr shell session | | |
Language를 지정하지 않으면 none이 되어 highlighting하지 않습니다. none을 명시할 수도 있습니다.
.. code-block:: none
This would be a block of text styled with a background
and box, but with no syntax highlighting.렌더링 결과:
This would be a block of text styled with a background
and box, but with no syntax highlighting.Code block 단축 표기법도 있습니다. 소개 paragraph를 double colon ::으로 끝내고 다음 content를 space 세 칸으로 indent합니다. Output에는 colon 하나만 보이며 highlighting은 none입니다. 문서 앞의 .. highlight:: directive로 default language를 바꿀 수 있습니다.
Image
Image directive로 문서에 image를 포함합니다.
.. image:: ../../../../images/doc-gen-flow.png
:align: center
:alt: alt text for the imageCaption을 추가하려면 figure directive를 사용합니다.
.. figure:: ../../../../images/doc-gen-flow.png
:alt: image description
Caption for the figureFile name은 document source file을 기준으로 한 상대 경로입니다. Source 옆 images folder 사용을 권장합니다. Browser가 처리하는 JPEG, PNG, GIF, SVG를 지원하며 필요한 크기만 사용합니다. 보통 폭은 최소 500px, 최대 1000px이고 특별히 큰 image가 명확성에 필요하지 않으면 250KB를 넘기지 않습니다.
Tab, space와 indent
reST에서는 indent가 의미를 가지며 space 사용을 권장합니다. 불필요한 indent도 의도치 않게 rendering을 바꿀 수 있습니다. List와 directive content는 앞 line에서 첫 non-whitespace 위치에 맞춥니다.
* List item that spans multiple lines of text
showing where to indent the continuation line.
1. And for numbered list items, the continuation
line should align with the text of the line above.
.. code-block::
The text within a directive block should align with the
first character of the directive name.추가 요구 사항은 Zephyr Coding Style을 참고하십시오.
zephyr-app-commands directive
Application을 build·flash하는 데 필요한 shell command를 일관된 문서 형식으로 생성하는 Zephyr directive입니다. qemu_x86에서 samples/hello_world를 build하는 command는 다음처럼 생성합니다.
.. zephyr-app-commands::
:zephyr-app: samples/hello_world
:board: qemu_x86
:goals: buildDirective option 19개는 다음과 같습니다.
:tool:cmake,west,all가운데 사용할 tool입니다. 기본값은west입니다.:app:Build할 application path입니다.
:zephyr-app:Upstream Zephyr repository에 있는 build 대상 application path입니다.
:app:과 함께 쓸 수 없습니다.:cd-into:설정하면
:app:folder 바깥이 아니라 그 안에서 실행하는 build instruction을 만듭니다.:generator:ninja또는makebuild system을 생성합니다. 기본값은ninja이며 대소문자를 구별하지 않습니다.:host-os:unix,win,all가운데 instruction 대상 host OS입니다. 기본값은all입니다.:board:설정하면 application build가 지정 board를 target으로 합니다.
:shield:설정하면 지정 shield를 target으로 하며 쉼표로 구분한 여러 shield를 제공할 수 있습니다.
:conf:설정하면 지정 configuration file을 사용합니다. 여러 conf file은
"a.conf b.conf"처럼 공백 구분 목록을 따옴표로 감쌉니다.:gen-args:CMake 호출에 추가할 argument입니다.
:build-args:Build 호출에 추가할 argument입니다.
:snippets:Application을 함께 compile할 snippet 목록이며 쉼표로 여러 항목을 구분할 수 있습니다.
:build-dir:표준 build directory에 이 상대 Unix 구분 path를 덧붙입니다. 한 페이지에서 같은 application의 여러 build를 구분할 때 주로 사용합니다.
:build-dir-fmt:west config build.dir-fmt가 이 path로 설정됐다고 가정합니다.:build-dir:과 함께 쓸 수 없고tool=west에 의존합니다.:goals:build,flash,debug,debugserver,run중 수행할 일을 공백으로 구분합니다. 올바른 순서의 command를 생성합니다.:maybe-skip-config:Reader가 이미 build directory를 만들고 이동했을 수 있음을 나타내며 다시 할 필요가 없다는 문구로 조정합니다.
:compact:추가 comment line 없이 하나의 code block으로 output을 생성합니다.
:west-args:West 호출에 추가할 argument이며 CMake에서는 무시합니다.
:flash-args:Flash 호출에 추가할 argument입니다.
위 directive의 생성 HTML output:
# From the root of the zephyr repository
west build -b qemu_x86 samples/hello_world대체 tab content
Tabbed interface로 reader에게 대체 content를 제공할 수 있습니다. Tab을 누르면 해당 content를 표시합니다.
.. tabs::
.. tab:: Apples
Apples are green, or sometimes red.
.. tab:: Pears
Pears are green.
.. tab:: Oranges
Oranges are orange.렌더링 결과:
Apples are green, or sometimes red.
Pears are green.
Oranges are orange.
Tab을 group으로 묶으면 한 영역의 현재 tab을 바꿀 때 page 전체에서 같은 이름의 tab도 함께 바뀝니다. 예를 들어 첫 group의 Linux·macOS·Windows 선택은 둘째 group의 같은 OS 선택과 동기화됩니다.
Linux Line 1 · macOS Line 1 · Windows Line 1
Linux Line 2 · macOS Line 2 · Windows Line 2
.. tab:: 대신 .. group-tab::을 사용합니다. 내부적으로 Zephyr setup에 포함된 sphinx-tabs extension을 사용합니다. Tab 안에는 heading을 제외한 code block, ordered·unordered list, picture, paragraph 등 대부분의 content를 넣을 수 있습니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.