Skip to content

Commit 4f1272d

Browse files
authored
Merge branch 'latest' into onvember/gh-1782
2 parents 58fc5ef + c5a1b21 commit 4f1272d

File tree

13 files changed

+1356
-1442
lines changed

13 files changed

+1356
-1442
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.. //Here is the first comment.
2+
.. //Here is the second comment.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
:file:`/usr/bin/example.py`
2+
3+
:file:`/usr/{dirname}/example.py`
4+
5+
:file:`/usr/{dirname}/{filename.ext}`
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.. cssclass:: highlight
2+
.. parsed-literal::
3+
4+
:samp:`box.space.{space-name}:create_index('{index-name}')`

doc/contributing/docs/markup/code.rst

Lines changed: 112 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,150 @@
11
Writing about code
22
==================
33

4+
When writing articles, you need to format code specially, separating it from
5+
other text. This document will guide you through typical cases when
6+
it is recommended to use code highlighting.
7+
8+
Defining what code is
9+
---------------------
10+
11+
In general, code is any text, processed by a machine. It is also probably code
12+
if the expression contains characters that ordinary words do not have,
13+
such as ``_, {}, [ ], .``.
14+
Also, you should format the expression as code if it fits at least one
15+
of the items in the list below:
16+
17+
* parts of a programming language: names of classes, variables, and functions,
18+
short expressions, data types and so on,
19+
* multiline fragments of application logs,
20+
* example link which the reader will not open: ``example.com``, ``https://example.com:80``,
21+
* parts of URL, like port number,
22+
* package names,
23+
* CLI app names.
24+
25+
Items we don't format as code:
26+
27+
* names of products, organizations and services, for example, Tarantool,
28+
memtx, vinyl
29+
* well-established terms such as stdin and stdout
30+
31+
Keep in mind that grammar doesn't apply to code, even inline.
32+
33+
* Correct: "use ``shellcheck`` to analyze your Bash code".
34+
* Incorrect: "``shellcheck`` your Bash code". Please do not use code
35+
as a verb.
36+
* Even worse: "shellcheck your Bash code". There's no such word in English
37+
and we don't explain what to use.
38+
* Cursed: "try ``shellchecking`` your Bash code". There's no such word
39+
and no such application.
40+
41+
Code blocks and inline code
42+
---------------------------
43+
44+
If you have to choose between inline code and code block highlighting,
45+
pay attention to the following guidelines:
46+
447
Code snippets
5-
-------------
48+
~~~~~~~~~~~~~
49+
50+
Use code blocks when you have to highlight multiple lines of code.
51+
Also, use it if your code snippet contains a standalone element
52+
that is not a part of the article's text.
653

754
For code snippets, we use the ``code-block:: language``
8-
`directive <https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-code-block>`_
9-
with an appropriate highlighting language.
55+
`directive <https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-code-block>`_.
56+
You can enable syntax highlighting if you specify the language for the snippet.
1057
The most commonly used highlighting languages are:
1158

1259
* ``tarantoolsession``—interactive Tarantool session,
1360
where command lines start with ``tarantlool>`` prompt.
14-
* ``console``—interactive console session, where command lines start with ``$`` or ``#``.
61+
* ``console``—interactive console session, where command lines
62+
start with ``$`` or ``#``.
1563
* ``lua``, ``bash`` or ``c`` for programming languages.
1664
* ``text`` for cases when we want the code block to have no highlighting.
1765

18-
Sphinx uses the Pygments library for highlighing source code.
66+
Sphinx uses the Pygments library for highlighting source code.
1967
For a complete list of possible languages, see the
2068
`list of Pygments lexers <https://pygments.org/docs/lexers/>`_.
2169

2270
For example, a code snippet in Lua:
2371

24-
.. literalinclude:: _includes/lua.rst
25-
:language: rst
72+
.. literalinclude:: _includes/lua.rst
73+
:language: rst
2674

2775
Lua syntax is highlighted in the output:
2876

29-
.. include:: _includes/lua.rst
77+
.. include:: _includes/lua.rst
78+
79+
Note that in code blocks you can write comments and translate them:
80+
81+
.. literalinclude:: _includes/comment.rst
82+
:language: rst
3083

3184
Inline code
32-
-----------
85+
~~~~~~~~~~~
86+
87+
Use inline code when you need to wrap a short snippet of code in text, such as
88+
variable name or function definition. Keep in mind that inline code
89+
doesn't have syntax highlighting.
3390

3491
To format some inline text as ``code``, enclose it with double ````` characters
3592
or use the ``:code:`` role:
3693

37-
.. literalinclude:: _includes/inline-code.rst
38-
:language: rst
94+
.. literalinclude:: _includes/inline-code.rst
95+
:language: rst
3996

4097
Both options produce the same output:
4198

42-
.. include:: _includes/inline-code.rst
99+
.. include:: _includes/inline-code.rst
100+
101+
102+
Notes on using inline-code
103+
^^^^^^^^^^^^^^^^^^^^^^^^^^
104+
105+
* If you have expressions such as ``id==4``, you should format the whole
106+
expression as code inline. Also, you can use the words "equals",
107+
"doesn't equal" or other similar words without formatting expression
108+
as code. Both variants are correct.
109+
110+
* Inline code can be used to highlight expressions that are hard to read,
111+
for example, words containing ``il``, ``Il`` or ``O0``.
112+
43113

44114
Highlighting variables in code
45115
------------------------------
46116

47-
If you need to highlight variables in code inline, use the ``:samp:`` role,
48-
like this:
117+
If you need to mark up a placeholder inside code inline, use the ``:samp:``
118+
role, like this:
119+
120+
.. literalinclude:: _includes/samp.rst
121+
:language: rst
122+
123+
And you will get this:
124+
125+
.. include:: _includes/samp.rst
126+
127+
If you need to mark up a placeholder in code block, use
128+
the following syntax:
129+
130+
.. literalinclude:: _includes/highlight.rst
131+
:language: rst
132+
133+
The output will look like this:
134+
135+
.. include:: _includes/highlight.rst
136+
137+
Formatting file and directory names
138+
-----------------------------------
139+
140+
If you need to highlight some file standalone name or path to file in text, use
141+
the ``:file:`` role.
142+
You can use curly braces inside this role
143+
to mark up a replaceable part:
49144

50-
.. literalinclude:: _includes/samp.rst
51-
:language: rst
145+
.. literalinclude:: _includes/file.rst
146+
:language: rst
52147

53148
And you will get this:
54149

55-
.. include:: _includes/samp.rst
150+
.. include:: _includes/file.rst

0 commit comments

Comments
 (0)