How to write code blocks in Sphinx#
Use either literal block or code-block directive.
Literal Block#
Example:
サンプル::
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
Output
Sample:
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
code-block#
Example:
.. code-block:: python
:caption: サンプル
:linenos:
:emphasize-lines: 4
def factorial(x):
if x == 0:
return 1
# ライン強調テスト
else:
return x * factorial(x - 1)
Output
1def factorial(x):
2 if x == 0:
3 return 1
4 # 強調
5 else:
6 return x * factorial(x - 1)