e5aebd15059c7835d0b0767e4953b92cb6976e01
[platform/upstream/doxygen.git] / doc / markdown.doc
1 /******************************************************************************
2  *
3  * 
4  *
5  * Copyright (C) 1997-2015 by Dimitri van Heesch.
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation under the terms of the GNU General Public License is hereby 
9  * granted. No representations are made about the suitability of this software 
10  * for any purpose. It is provided "as is" without express or implied warranty.
11  * See the GNU General Public License for more details.
12  *
13  * Documents produced by Doxygen are derivative works derived from the
14  * input used in their production; they are not affected by this license.
15  *
16  */
17 /*! \page markdown Markdown support
18
19 [TOC]
20
21 [Markdown] support 
22 was introduced in doxygen version 1.8.0. It is a plain text formatting
23 syntax written by John Gruber, with the following underlying design goal:
24
25 > The design goal for Markdown's formatting syntax is to 
26 > make it as readable as possible. The idea is that a Markdown-formatted 
27 > document should be publishable as-is, as plain text, without 
28 > looking like it's been marked up with tags or formatting instructions. 
29 > While Markdown's syntax has been influenced by several existing 
30 > text-to-HTML filters, the single biggest source of inspiration 
31 > for Markdown's syntax is the format of plain text email.
32
33 In the \ref markdown_std "next section" the standard Markdown features
34 are briefly discussed. The reader is referred to the [Markdown site][markdown]
35 for more details.
36
37 Some enhancements were made, for instance [PHP Markdown Extra][mdextra], and
38 [GitHub flavored Markdown][github]. The section \ref markdown_extra discusses
39 the extensions that doxygen supports.
40
41 Finally section \ref markdown_dox discusses some specifics for doxygen's
42 implementation of the Markdown standard.
43
44 [markdown]: http://daringfireball.net/projects/markdown/ 
45 [mdextra]:  https://michelf.ca/projects/php-markdown/extra/
46 [github]:   https://github.github.com/github-flavored-markdown/
47
48 \section markdown_std Standard Markdown
49
50 \subsection md_para Paragraphs
51
52 Even before doxygen had Markdown support it supported the same way
53 of paragraph handling as Markdown: to make a paragraph you just separate
54 consecutive lines of text by one or more blank lines.
55
56 An example:
57
58     Here is text for one paragraph.
59
60     We continue with more text in another paragraph.
61
62 \subsection md_headers Headers
63
64 Just like Markdown, doxygen supports two types of headers
65
66 Level 1 or 2 headers can be made as the follows
67
68     This is a level 1 header
69     ========================
70
71     This is a level 2 header
72     ------------------------
73
74 A header is followed by a line containing only ='s or -'s.
75 Note that the exact amount of ='s or -'s is not important as long as
76 there are at least two.
77
78 Alternatively, you can use #'s at the start of a line to make a header. 
79 The number of #'s at the start of the line determines the level (up to 6 levels are supported).
80 You can end a header by any number of #'s.
81
82 Here is an example:
83
84     # This is a level 1 header
85
86     ### This is level 3 header #######
87
88 \subsection md_blockquotes Block quotes
89
90 Block quotes can be created by starting each line with one or more >'s, 
91 similar to what is used in text-only emails.
92
93     > This is a block quote
94     > spanning multiple lines
95
96 Lists and code blocks (see below) can appear inside a quote block.
97 Quote blocks can also be nested.
98
99 Note that doxygen requires that you put a space after the (last) > character
100 to avoid false positives, i.e. when writing
101
102     0  if OK\n
103     >1 if NOK
104
105 the second line will not be seen as a block quote.
106
107 \subsection md_lists Lists
108
109 Simple bullet lists can be made by starting a line with -, +, or *.
110
111     - Item 1
112
113       More text for this item.
114
115     - Item 2
116       + nested list item.
117       + another nested item.
118     - Item 3
119
120 List items can span multiple paragraphs (if each paragraph starts with
121 the proper indentation) and lists can be nested.
122 You can also make a numbered list like so
123
124     1. First item.
125     2. Second item.
126
127 Make sure to also read \ref mddox_lists for doxygen specifics.
128
129 \subsection md_codeblock Code Blocks
130
131 Preformatted verbatim blocks can be created by indenting
132 each line in a block of text by at least 4 extra spaces
133
134     This a normal paragraph
135
136         This is a code block
137
138     We continue with a normal paragraph again.
139
140 Doxygen will remove the mandatory indentation from the code block.
141 Note that you cannot start a code block in the middle of a paragraph
142 (i.e. the line preceding the code block must be empty).
143
144 See section \ref mddox_code_blocks for more info how doxygen handles
145 indentation as this is slightly different than standard Markdown.
146
147 \subsection md_rulers Horizontal Rulers
148
149 A horizontal ruler will be produced for lines containing at least three or more
150 hyphens, asterisks, or underscores. The line may also include any amount of whitespace.
151
152 Examples:
153
154     - - -
155     ______
156
157 Note that using asterisks in comment blocks does not work. See 
158 \ref mddox_stars for details.
159
160 \subsection md_emphasis Emphasis
161
162 To emphasize a text fragment you start and end the fragment with an underscore or star.
163 Using two stars or underscores will produce strong emphasis.
164
165 Examples:
166
167 *    *single asterisks*
168 *
169 *    _single underscores_
170 *
171 *    **double asterisks**
172 *
173 *    __double underscores__
174
175 See section \ref mddox_emph_spans for more info how doxygen handles
176 emphasis spans slightly different than standard Markdown.
177
178 \subsection md_codespan code spans
179
180 To indicate a span of code, you should wrap it in backticks (`). Unlike code blocks,
181 code spans appear inline in a paragraph. An example:
182
183     Use the `printf()` function.
184
185 To show a literal backtick inside a code span use double backticks, i.e.
186
187     To assign the output of command `ls` to `var` use ``var=`ls```.
188
189 See section \ref mddox_code_spans for more info how doxygen handles
190 code spans slightly different than standard Markdown.
191
192 \subsection md_links Links
193
194 Doxygen supports both styles of make links defined by Markdown: *inline* and *reference*.
195
196 For both styles the link definition starts with the link text delimited by [square 
197 brackets].
198
199 \subsubsection md_inlinelinks Inline Links
200
201 For an inline link the link text is followed by a URL and an optional link title which
202 together are enclosed in a set of regular parenthesis. 
203 The link title itself is surrounded by quotes.
204
205 Examples:
206
207     [The link text](http://example.net/)
208     [The link text](http://example.net/ "Link title")
209     [The link text](/relative/path/to/index.html "Link title") 
210     [The link text](somefile.html) 
211
212 In addition doxygen provides a similar way to link a documented entity:
213
214     [The link text](@ref MyClass) 
215
216 \subsubsection md_reflinks Reference Links
217
218 Instead of putting the URL inline, you can also define the link separately
219 and then refer to it from within the text.
220
221 The link definition looks as follows:
222
223     [link name]: http://www.example.com "Optional title"
224
225 Instead of double quotes also single quotes or parenthesis can
226 be used for the title part.
227
228 Once defined, the link looks as follows
229   
230     [link text][link name]
231
232 If the link text and name are the same, also
233
234     [link name][]
235
236 or even
237
238     [link name]
239
240 can be used to refer to the link.
241 Note that the link name matching is not case sensitive
242 as is shown in the following example:
243
244     I get 10 times more traffic from [Google] than from
245     [Yahoo] or [MSN].
246
247     [google]: http://google.com/        "Google"
248     [yahoo]:  http://search.yahoo.com/  "Yahoo Search"
249     [msn]:    http://search.msn.com/    "MSN Search"
250
251 Link definitions will not be visible in the output.
252
253 Like for inline links doxygen also supports \@ref inside a link definition:
254
255     [myclass]: @ref MyClass "My class"
256
257 \subsection md_images Images
258
259 Markdown syntax for images is similar to that for links.
260 The only difference is an additional ! before the link text.
261
262 Examples:
263
264     ![Caption text](/path/to/img.jpg)
265     ![Caption text](/path/to/img.jpg "Image title")
266     ![Caption text][img def]
267     ![img def]
268
269     [img def]: /path/to/img.jpg "Optional Title"
270
271 Also here you can use \@ref to link to an image:
272
273     ![Caption text](@ref image.png)
274     ![img def]
275
276     [img def]: @ref image.png "Caption text"
277
278 The caption text is optional.
279
280 \subsection md_autolink Automatic Linking
281
282 To create a link to an URL or e-mail address Markdown supports the following
283 syntax:
284
285     <http://www.example.com>
286     <https://www.example.com>
287     <ftp://www.example.com>
288     <mailto:address@example.com>
289     <address@example.com>
290
291 Note that doxygen will also produce the links without the angle brackets.
292
293 \section markdown_extra Markdown Extensions
294
295 \subsection md_toc Table of Contents
296
297 Doxygen supports a special link marker `[TOC]` which can be placed in a page
298 to produce a table of contents at the start of the page, listing all sections.
299
300 Note that using `[TOC]` is the same as using a
301 \ref cmdtableofcontents "\\tableofcontents" command.
302
303 \subsection md_tables Tables
304
305 Of the features defined by "Markdown Extra" is support for
306 <a href="https://michelf.ca/projects/php-markdown/extra/#table">simple tables</a>:
307
308 A table consists of a header line, a separator line, and at least one
309 row line. Table columns are separated by the pipe (|) character.
310
311 Here is an example:
312
313     First Header  | Second Header
314     ------------- | -------------
315     Content Cell  | Content Cell 
316     Content Cell  | Content Cell 
317
318 which will produce the following table:
319
320 First Header  | Second Header
321 ------------- | -------------
322 Content Cell  | Content Cell 
323 Content Cell  | Content Cell 
324
325 Column alignment can be controlled via one or two colons 
326 at the header separator line:
327
328     | Right | Center | Left  |
329     | ----: | :----: | :---- |
330     | 10    | 10     | 10    |
331     | 1000  | 1000   | 1000  |
332
333 which will look as follows:
334
335 | Right | Center | Left  |
336 | ----: | :----: | :---- |
337 | 10    | 10     | 10    |
338 | 1000  | 1000   | 1000  |
339
340 Additionally, column and row spans are supported.  Using a caret ("^")
341 in a cell indicates that the cell above should span rows.  Sequences
342 of carets may be used for any number of row spans.  For example:
343
344     | Right | Center | Left  |
345     | ----: | :----: | :---- |
346     | 10    | 10     | 10    |
347     | ^     | 1000   | 1000  |
348
349 which will look as follows:
350
351 | Right | Center | Left  |
352 | ----: | :----: | :---- |
353 | 10    | 10     | 10    |
354 | ^     | 1000   | 1000  |
355
356 Column spans are supported by means of directly adjacent vertical bars
357 ("|").  Each additional vertical bar indicates an additional column to
358 be spanned.  To put it another way, a single vertical bar indicates a
359 single column span, two vertical bars indicates a 2 columns span, and
360 so on.  For example:
361
362     | Right | Center | Left  |
363     | ----: | :----: | :---- |
364     | 10    | 10     | 10    |
365     | 1000  |||
366
367 which will look as follows:
368
369 | Right | Center | Left  |
370 | ----: | :----: | :---- |
371 | 10    | 10     | 10    |
372 | 1000  |||   
373
374 For more complex tables in doxygen please have a look at: \ref tables
375
376 \subsection md_fenced Fenced Code Blocks
377
378 Another feature defined by "Markdown Extra" is support for
379 <a href="https://michelf.ca/projects/php-markdown/extra/#fenced-code-blocks">
380 fenced code blocks</a>:
381
382 A fenced code block does not require indentation, and is
383 defined by a pair of "fence lines". Such a line consists of 3 or
384 more tilde (~) characters on a line. The end of the block should have the
385 same number of tildes. Here is an example:
386
387
388     This is a paragraph introducing:
389
390     ~~~~~~~~~~~~~~~~~~~~~
391     a one-line code block
392     ~~~~~~~~~~~~~~~~~~~~~
393
394 By default the output is the same as for a normal code block.
395
396 For languages supported by doxygen you can also make the code block
397 appear with syntax highlighting. To do so you need to 
398 indicate the typical file extension that corresponds to the 
399 programming language after the opening fence. For highlighting according
400 to the Python language for instance, you would need to write the following:
401
402     ~~~~~~~~~~~~~{.py}
403     # A class
404     class Dummy:
405         pass
406     ~~~~~~~~~~~~~
407
408 which will produce:
409 ~~~~~~~~~~~~~{.py}
410 # A class
411 class Dummy:
412     pass
413 ~~~~~~~~~~~~~
414
415 and for C you would write:
416
417     ~~~~~~~~~~~~~~~{.c}
418     int func(int a,int b) { return a*b; }
419     ~~~~~~~~~~~~~~~
420
421 which will produce:
422
423 ~~~~~~~~~~~~~~~{.c}
424 int func(int a,int b) { return a*b; }
425 ~~~~~~~~~~~~~~~
426
427 The curly braces and dot are optional by the way.
428
429 Another way to denote fenced code blocks is to use 3 or more backticks (```):
430
431     ```
432     also a fenced code block
433     ```
434
435 \subsection md_header_id Header Id Attributes
436
437 Standard Markdown has no support for labeling headers, which
438 is a problem if you want to link to a section.
439
440 PHP Markdown Extra allows you to label a header by adding
441 the following to the header
442
443     Header 1                {#labelid}
444     ========
445
446     ## Header 2 ##          {#labelid2}
447
448 To link to a section in the same comment block you can use
449
450     [Link text](#labelid)
451
452 to link to a section in general, doxygen allows you to use \@ref
453
454     [Link text](@ref labelid)
455
456 Note this only works for the headers of level 1 to 4.
457
458 \section markdown_dox Doxygen specifics
459
460 Even though doxygen tries to following the Markdown standard as closely as
461 possible, there are couple of deviation and doxygen specifics additions.
462
463 \subsection md_page_header Including Markdown files as pages
464
465 Doxygen can process files with Markdown formatting. 
466 For this to work the extension for such a file should 
467 be `.md` or `.markdown` (see 
468 \ref cfg_extension_mapping "EXTENSION_MAPPING" if your Markdown files have 
469 a different extension, and use `md` as the name of the parser).
470 Each file is converted to a page (see the \ref cmdpage "page" command for
471 details). 
472
473 By default the name and title of the page are derived from the file name.
474 If the file starts with a level 1 header however, it is used as the title
475 of the page. If you specify a label for the 
476 header (as shown in \ref md_header_id) doxygen will use that as the
477 page name. 
478
479 If the label is called `index` or `mainpage` doxygen will put the
480 documentation on the front page (`index.html`).
481
482 Here is an example of a file `README.md` that will appear as the main page
483 when processed by doxygen:
484
485     My Main Page                         {#mainpage}
486     ============
487
488     Documentation that will appear on the main page
489
490 If a page has a label you can link to it using \ref cmdref "\@ref" as 
491 is shown above. To refer to a markdown page without
492 such label you can simple use the file name of the page, e.g.
493
494     See [the other page](other.md) for more info.
495
496 \subsection md_html_blocks Treatment of HTML blocks
497
498 Markdown is quite strict in the way it processes block-level HTML:
499
500 > block-level HTML elements — e.g. 
501 > `<div>`, `<table>`, `<pre>`, `<p>`, etc. — 
502 > must be separated from surrounding content by blank lines, 
503 > and the start and end tags of the block should not be indented 
504 > with tabs or spaces.
505
506 Doxygen does not have this requirement, and will also process 
507 Markdown formatting inside such HTML blocks. The only exception is
508 `<pre>` blocks, which are passed untouched (handy for ASCII art).
509
510 Doxygen will not process Markdown formatting inside verbatim or code blocks,
511 and in other sections that need to be processed without changes
512 (for instance formulas or inline dot graphs).
513
514 \subsection mddox_code_blocks Code Block Indentation
515
516 Markdown allows both a single tab or 4 spaces to start a code block.
517 Since doxygen already replaces tabs by spaces before doing Markdown
518 processing, the effect will only be same if TAB_SIZE in the config file
519 has been set to 4. When it is set to a higher value spaces will be
520 present in the code block. A lower value will prevent a single tab to be 
521 interpreted as the start of a code block.
522
523 With Markdown any block that is indented by 4 spaces (and 8 spaces
524 inside lists) is treated as a code block. This indentation amount
525 is absolute, i.e. counting from the start of the line.
526
527 Since doxygen comments can appear at any indentation level
528 that is required by the programming language, it
529 uses a relative indentation instead. The amount of 
530 indentation is counted relative to the preceding paragraph.
531 In case there is no preceding paragraph (i.e. you want to start with a
532 code block), the minimal amount of indentation of the whole comment block 
533 is used as a reference.
534
535 In most cases this difference does not result in different output.
536 Only if you play with the indentation of paragraphs the difference
537 is noticeable:
538
539     text
540
541      text
542
543       text
544   
545        code
546
547 In this case Markdown will put the word code in a code block,
548 whereas doxygen will treat it as normal text, since although the absolute
549 indentation is 4, the indentation with respect to the previous paragraph
550 is only 1.
551
552 Note that list markers are not counted when determining the
553 relative indent:
554
555     1.  Item1
556
557         More text for item1
558
559     2.  Item2
560
561             Code block for item2
562
563 For Item1 the indentation is 4 (when treating the list marker as whitespace), 
564 so the next paragraph "More text..." starts at the same indentation level 
565 and is therefore not seen as a code block.
566
567 \subsection mddox_emph_spans Emphasis limits
568
569 Unlike standard Markdown, doxygen will not touch internal underscores or
570 stars, so the following will appear as-is:
571
572     a_nice_identifier
573
574 Furthermore, a `*` or `_` only starts an emphasis if
575 - it is followed by an alphanumerical character, and
576 - it is preceded by a space, newline, or one the following characters `<{([,:;`
577
578 An emphasis ends if
579 - it is not followed by an alphanumerical character, and
580 - it is not preceded by a space, newline, or one the following characters `({[<=+-\@`
581
582 Lastly, the span of the emphasis is limited to a single paragraph.
583
584
585 \subsection mddox_code_spans Code Spans Limits
586
587 Note that unlike standard Markdown, doxygen leaves the following untouched.
588
589     A `cool' word in a `nice' sentence.
590
591 In other words; a single quote cancels the special treatment of a code span
592 wrapped in a pair of backtick characters. This extra restriction was
593 added for backward compatibility reasons.
594
595 \subsection mddox_lists Lists Extensions
596
597 With Markdown two lists separated by an empty line are joined together into
598 a single list which can be rather unexpected and many people consider it to
599 be a bug. Doxygen, however, will make two separate lists as you would expect.
600
601 Example:
602   
603     - Item1 of list 1
604     - Item2 of list 1
605
606     1. Item1 of list 2
607     2. Item2 of list 2
608
609 With Markdown the actual numbers you use to mark the list have no 
610 effect on the HTML output Markdown produces. I.e. standard Markdown treats the 
611 following as one list with 3 numbered items:
612
613     1. Item1
614     1. Item2
615     1. Item3
616
617 Doxygen however requires that the numbers used as marks are in 
618 strictly ascending order, so the above example would produce 3 lists 
619 with one item. An item with an equal or lower number than 
620 the preceding item, will start a new list. For example:
621
622     1. Item1 of list 1
623     3. Item2 of list 1
624     2. Item1 of list 2
625     4. Item2 of list 2
626
627 will produce:
628
629 1. Item1 of list 1
630 3. Item2 of list 1
631 2. Item1 of list 2
632 4. Item2 of list 2
633     
634 Historically doxygen has an additional way to create numbered 
635 lists by using `-#` markers:
636
637     -# item1
638     -# item2
639
640 \subsection mddox_stars Use of asterisks
641
642 Special care has to be taken when using *'s in a comment block 
643 to start a list or make a ruler.
644
645 Doxygen will strip off any leading *'s from the comment before doing
646 Markdown processing. So although the following works fine
647
648 @verbatim
649     /** A list:
650      *  * item1
651      *  * item2
652      */
653 @endverbatim
654
655 When you remove the leading *'s doxygen will strip the other stars
656 as well, making the list disappear!
657
658 Rulers created with *'s will not be visible at all. They only work
659 in Markdown files.
660
661 \subsection mddox_limits Limits on markup scope
662
663 To avoid that a stray * or _ matches something many paragraphs later,
664 and shows everything in between with emphasis, doxygen limits the scope
665 of a * and _ to a single paragraph.
666
667 For a code span, between the starting and ending backtick only two
668 new lines are allowed. 
669
670 Also for links there are limits; the link text, and link title each can
671 contain only one new line, the URL may not contain any newlines. 
672
673 \section markdown_debug Debugging of problems
674
675 When doxygen parses the source code it first extracts the comments blocks,
676 then passes these through the Markdown preprocessor. The output of the
677 Markdown preprocessing consists of text with \ref cmd_intro "special commands" 
678 and \ref htmlcmds "HTML commands".
679 A second pass takes the output of the Markdown preprocessor and
680 converts it into the various output formats.
681
682 During Markdown preprocessing no errors are produced. Anything that
683 does not fit the Markdown syntax is simply passed on as-is. In the subsequent
684 parsing phase this could lead to errors, which may not always be obvious
685 as they are based on the intermediate format.
686
687 To see the result after Markdown processing you can run doxygen with the
688 `-d Markdown` option. It will then print each comment block before and
689 after Markdown processing.
690
691 \htmlonly
692 Go to the <a href="lists.html">next</a> section or return to the
693  <a href="index.html">index</a>.
694 \endhtmlonly
695
696 */