Debian Codegraph @

documentation/source/markups.rst

raw
1
2 Supported Markups
3 =================
4
5 All comments in your code must be formatted in a doxygen-compliant way so that
6 doxygen can do its job. Doxygen provides support for formatting your text with
7 tags, such as ``\b`` for adding bold text, this information appears in the xml
8 output and Breathe attempts to reproduce it accurately.
9
10 In addition to this, is it possible to add reStructuredText into your comments
11 within appropriately demarcated sections.
12
13 reStructuredText
14 ----------------
15
16 .. cpp:namespace:: @ex_markups_rst
17
18 Breathe supports reStructuredText within doxygen **verbatim** blocks which begin
19 with the markup **embed:rst**. This means that a comment block like this:
20
21 .. code-block:: cpp
22
23 /*!
24 Inserting additional reStructuredText information.
25 \verbatim embed:rst
26 .. note::
27
28 This reStructuredText has been handled correctly.
29 \endverbatim
30 */
31
32 Will be rendered as:
33
34 .. doxygenfunction:: TestClass::rawVerbatim
35 :project: rst
36 :no-link:
37
38 Handling Leading Asterisks
39 ~~~~~~~~~~~~~~~~~~~~~~~~~~
40
41 .. cpp:namespace:: @ex_markups_leading_star
42
43 Note that doxygen captures **all** content in a **verbatim** block. This can
44 be rather an annoyance if you use a leading-asterisk style of comment block
45 such as the following:
46
47 .. code-block:: cpp
48
49 /*!
50 * Inserting additional reStructuredText information.
51 *
52 * \verbatim embed:rst
53 * Some example code
54 *
55 * .. code-block:: cpp
56 *
57 * int example(int x) {
58 * return x * 2;
59 * }
60 * \endverbatim
61 */
62
63 As the leading asterisks are captured in the **verbatim** block this will
64 appear to be an incorrectly formatted bullet list. Due to the syntactical
65 problems Sphinx will issue warnings and the block will render as:
66
67 ..
68 Here we fake the bad output without actually using a bad example otherwise
69 we'll get warnings in the build output.
70
71 void **rawBadAsteriskVerbatim**\ ()
72
73 Inserting additional reStructuredText information.
74
75 - Some example code:
76 - int example(int x) {
77 - return x \* 2;
78 - }
79
80 To prevent this, use an **embed:rst:leading-asterisk** tag:
81
82 .. code-block:: cpp
83
84 /*!
85 * Inserting additional reStructuredText information.
86 *
87 * \verbatim embed:rst:leading-asterisk
88 * Some example code::
89 *
90 * int example(int x) {
91 * return x * 2;
92 * }
93 * \endverbatim
94 */
95
96 This will appropriately handle the leading asterisks and render as:
97
98 ----
99
100 .. doxygenfunction:: TestClass::rawLeadingAsteriskVerbatim
101 :project: rst
102
103 ----
104
105 Handling Leading Slashes
106 ~~~~~~~~~~~~~~~~~~~~~~~~
107
108 .. cpp:namespace:: @ex_markups_leading_slash
109
110 Similar troubles can be encountered when using comment blocks that start with a
111 triple forward slash. For example:
112
113 .. code-block:: cpp
114
115 /// Some kind of method
116 ///
117 /// @param something a parameter
118 /// @returns the same value provided in something param
119 ///
120 /// @verbatim embed:rst:leading-slashes
121 /// .. code-block:: c
122 /// :linenos:
123 ///
124 /// bool foo(bool something) {
125 /// return something;
126 /// };
127 ///
128 /// @endverbatim
129 /// @note Documentation using `///` should begin and end in a blank line.
130
131 For these kinds of blocks, you can use an **embed:rst:leading-slashes** tag as
132 shown in the above example.
133
134 This will appropriately handle the leading slashes and render as:
135
136 ----
137
138 .. doxygenfunction:: TestClass::rawLeadingSlashesVerbatim
139 :project: rst
140
141 ----
142
143 Inline rST
144 ~~~~~~~~~~
145
146 .. cpp:namespace:: @ex_markups_inline
147
148 Normal verbatim elements result in block elements. But sometimes you'll want
149 to generate rST references where they need to be rendered inline with the text.
150 For example:
151
152 .. code-block:: cpp
153
154 /// Some kind of method
155 ///
156 /// @param something a parameter
157 /// @returns the same value provided in something param
158 ///
159 /// @verbatim embed:rst:inline some inline text @endverbatim
160
161 For these kinds of references, you can use an **embed:rst:inline** tag as
162 shown in the above example.
163
164 This will appropriately handle the leading slashes and render as:
165
166 ----
167
168 .. doxygenfunction:: TestClass::rawInlineVerbatim
169 :project: rst
170
171 .. doxygenfunction:: TestClass::rawVerbatim
172 :project: rst
173 :outline:
174
175 ----
176
177 Aliases
178 ~~~~~~~
179
180 .. cpp:namespace:: @ex_markups_aliases
181
182 To make these blocks appear as more appropriate doxygen-like markup in your
183 comments you can add the following aliases to your doxygen configuration file:
184
185 .. code-block:: text
186
187 ALIASES = "rst=^^\verbatim embed:rst^^"
188 ALIASES += "endrst=\endverbatim"
189
190 Which allow you to write comments like:
191
192 .. code-block:: cpp
193
194 /*!
195 Inserting additional reStructuredText information.
196
197 \rst
198
199 This is some funky non-xml compliant text: <& !><
200
201 .. note::
202
203 This reStructuredText has been handled correctly.
204 \endrst
205
206 This is just a standard verbatim block with code:
207
208 \verbatim
209 child = 0;
210 while( child = parent->IterateChildren( child ) )
211 \endverbatim
212
213 */
214
215 Which will be rendered as:
216
217 .. doxygenfunction:: TestClass::function
218 :project: rst
219
220 .. note::
221
222 The character sequence ``^^`` in an ALIAS definition inserts a line break.
223 The leading ``^^`` ensures that a RST ``\verbatim`` block never starts in a brief description
224 (which would break the output), even if you put it on the first line of a comment.
225 The trailing ``^^`` allows to start with RST content on the same line of the ``\rst`` command.
226
227 The ALIAS given above only works for comment blocks without a leading comment character on each line.
228 If you use a comment style with a leading comment character on each new line,
229 use these aliases instead:
230
231 .. code-block:: text
232
233 ALIASES = "rst=^^\verbatim embed:rst:leading-asterisk^^"
234 ALIASES += "endrst=\endverbatim"
235
236 Due to an `undocumented behavior in doxygen <https://github.com/doxygen/doxygen/issues/8907>`_,
237 all leading comment characters (``*``, ``///`` or ``//!``) encountered in a verbatim section
238 will be converted to asterisk (``*`` ) by Doxygen, when ``\verbatim`` is part of an alias.
239 Therefore, the ALIAS above works in all comment blocks with leading line comment characters.
240
241 If you want to hide reStructuredText output from Doxygen html and only include it in sphinx,
242 use the Doxygen command ``\xmlonly``.
243 This is an example alias that enables all RST sections in XML only:
244
245 .. code-block:: text
246
247 ALIASES = "rst=^^\xmlonly<verbatim>embed:rst:leading-asterisk^^"
248 ALIASES += "endrst=</verbatim>\endxmlonly"