]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/tools/quickbook/doc/block.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / tools / quickbook / doc / block.qbk
CommitLineData
7c673cae
FG
1[/
2 Copyright 2002,2004,2006 Joel de Guzman, Eric Niebler
3 Copyright 2010-2011 Daniel James
4
5 Distributed under the Boost Software License, Version 1.0.
6 (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8]
9
10[chapter Block Level Elements
11 [quickbook 1.6]
12 [compatibility-mode 1.5]
13 [id quickbook.syntax.block]
14 [source-mode teletype]
15]
16
17[#quickbook.ref.xinclude]
18[section:xinclude xinclude]
19
20You can include another XML file with:
21
22```
23[xinclude file.xml]
24```
25
26This is useful when file.xml has been generated by Doxygen and contains your
27reference section.
28
29=xinclude= paths are normally used unchanged in the generated documentation,
30which will not work if you wish them to be relative to the current quickbook
31file. Quickbook can add a =xml:base= attribute to the boostbook documentation
32to specify where =xinclude= files should be found. For example, if you wish
33them to be relative to the current quickbook file:
34
35 [article Article with xincludes
36 [quickbook 1.6]
37 [xmlbase .]
38 ]
39
40 [xinclude file.xml]
41
42Now the xinclude should work if =file.xml= is in the same directory as the
43quickbook file. Although it might not work if you distribute the generated
44files (as their relative directories can change).
45
46Say the article is generated in a sub-directory, by running something like:
47
48 quickbook article.qbk --output-file=output/article.xml
49
50This will generate a boostbook root tag:
51
52 <article id="article_with_xincludes"
53 last-revision="$Date: 2013/08/20 08:26:48 $"
54 xml:base=".."
55 xmlns:xi="http://www.w3.org/2001/XInclude">
56
57Because =xml:base= is set to =..=, the xml processor will know to look in
58the parent directory to find =file.xml=, which it comes across the
59=xi:include= tag.
60
61[endsect] [/xinclude]
62
63[#quickbook.ref.paragraphs]
64[section:paragraphs Paragraphs]
65
66Paragraphs start left-flushed and are terminated by two or more newlines. No
67markup is needed for paragraphs. QuickBook automatically detects paragraphs from
68the context. Block markups \[section, endsect, h1, h2, h3, h4, h5, h6, blurb,
69(block-quote) ':', pre, def, table and include \] may also terminate a paragraph.
70 [/ <-- There's a space here. Don't remove. this is intentianal, for testing]
71This is a new paragraph...
72
73[endsect] [/paragraphs]
74
75[#quickbook.ref.lists]
76[section:lists Lists]
77[#quickbook.ref.ordered_lists]
78[section:ordered_lists Ordered lists]
79
80[pre
81# One
82# Two
83# Three
84]
85
86will generate:
87
88# One
89# Two
90# Three
91
92[endsect] [/ordered_lists]
93[#quickbook.ref.list_hierarchies]
94[section:list_hierarchies List Hierarchies]
95
96List hierarchies are supported. Example:
97
98[pre
99# One
100# Two
101# Three
102 # Three.a
103 # Three.b
104 # Three.c
105# Four
106 # Four.a
107 # Four.a.i
108 # Four.a.ii
109# Five
110]
111
112will generate:
113
114# One
115# Two
116# Three
117 # Three.a
118 # Three.b
119 # Three.c
120# Fourth
121 # Four.a
122 # Four.a.i
123 # Four.a.ii
124# Five
125
126[endsect] [/list_hierarchies]
127[#quickbook.ref.long_list_lines]
128[section:long_list_lines Long List Lines]
129
130Long lines will be wrapped appropriately. Example:
131
132[pre
133# A short item.
134# A very long item. A very long item. A very long item.
135 A very long item. A very long item. A very long item.
136 A very long item. A very long item. A very long item.
137 A very long item. A very long item. A very long item.
138 A very long item. A very long item. A very long item.
139# A short item.
140]
141
142# A short item.
143# A very long item. A very long item. A very long item.
144 A very long item. A very long item. A very long item.
145 A very long item. A very long item. A very long item.
146 A very long item. A very long item. A very long item.
147 A very long item. A very long item. A very long item.
148# A short item.
149
150[endsect] [/long_list_lines]
151[#quickbook.ref.unordered_lists]
152[section:unordered_lists Unordered lists]
153
154```
155* First
156* Second
157* Third
158```
159
160will generate:
161
162* First
163* Second
164* Third
165
166[endsect] [/unordered_lists]
167[#quickbook.ref.mixed_lists]
168[section:mixed_lists Mixed lists]
169
170Mixed lists (ordered and unordered) are supported. Example:
171
172```
173# One
174# Two
175# Three
176 * Three.a
177 * Three.b
178 * Three.c
179# Four
180```
181
182will generate:
183
184# One
185# Two
186# Three
187 * Three.a
188 * Three.b
189 * Three.c
190# Four
191
192And...
193
194```
195# 1
196 * 1.a
197 # 1.a.1
198 # 1.a.2
199 * 1.b
200# 2
201 * 2.a
202 * 2.b
203 # 2.b.1
204 # 2.b.2
205 * 2.b.2.a
206 * 2.b.2.b
207```
208
209will generate:
210
211# 1
212 * 1.a
213 # 1.a.1
214 # 1.a.2
215 * 1.b
216# 2
217 * 2.a
218 * 2.b
219 # 2.b.1
220 # 2.b.2
221 * 2.b.2.a
222 * 2.b.2.b
223
224[endsect] [/mixed_lists]
225
226[#quickbook.ref.list_tags]
227[section:list_tags Explicit list tags]
228
229Sometimes the wiki-style list markup can be tricky to use, especially
230if you wish to include more complicated markup with the list. So in
231quickbook 1.6, an alternative way to mark up lists introduced:
232
233 [ordered_list [item1][item2]]
234
235is equivalent to:
236
237 # item1
238 # item2
239
240And:
241
242 [itemized_list [item1][item2]]
243
244is equivalent to:
245
246 * item1
247 * item2
248
249[endsect] [/list_tags]
250[endsect] [/lists]
251
252[#quickbook.ref.code]
253[section:code Code]
254
255Preformatted code starts with a space or a tab. The code will be
256syntax highlighted according to the current __source_mode__:
257
258[c++]
259
260 #include <iostream>
261
262 int main()
263 {
264 // Sample code
265 std::cout << "Hello, World\n";
266 return 0;
267 }
268
269[python]
270
271 import cgi
272
273 def cookForHtml(text):
274 '''"Cooks" the input text for HTML.'''
275
276 return cgi.escape(text)
277
278[teletype]
279
280Macros that are already defined are expanded in source code. Example:
281
282```
283[def __array__ [@http://www.boost.org/doc/html/array/reference.html array]]
284[def __boost__ [@http://www.boost.org/libs/libraries.htm boost]]
285
286 using __boost__::__array__;
287```
288
289Generates:
290
291[def __array__ [@http://www.boost.org/doc/html/array/reference.html array]]
292[def __boost__ [@http://www.boost.org/libs/libraries.htm boost]]
293
294 using __boost__::__array__;
295
296[endsect] [/code]
297
298[#quickbook.ref.escape_back]
299[section:escape_back Escaping Back To QuickBook]
300
301Inside code, code blocks and inline code, QuickBook does not allow any
302markup to avoid conflicts with the target syntax (e.g. c++). In case you
303need to switch back to QuickBook markup inside code, you can do so using a
304language specific /escape-back/ delimiter. In C++ and Python, the delimiter
305is the double tick (back-quote): "\`\`" and "\`\`". Example:
306
307```
308void ``[@http://en.wikipedia.org/wiki/Foo#Foo.2C_Bar_and_Baz foo]``()
309{
310}
311```
312
313Will generate:
314
315 void ``[@http://en.wikipedia.org/wiki/Foo#Foo.2C_Bar_and_Baz foo]``()
316 {
317 }
318
319When escaping from code to QuickBook, only phrase level markups are
320allowed. Block level markups like lists, tables etc. are not allowed.
321
322[endsect] [/escaping_back_to_quickbook]
323
324[#quickbook.ref.preformatted]
325[section:preformatted Preformatted]
326
327Sometimes, you don't want some preformatted text to be parsed as source code. In such
328cases, use the [^\[pre ... \]] markup block.
329
330```
331[pre
332
333 Some *preformatted* text Some *preformatted* text
334
335 Some *preformatted* text Some *preformatted* text
336
337 Some *preformatted* text Some *preformatted* text
338
339]
340```
341
342Spaces, tabs and newlines are rendered as-is. Unlike all quickbook block level
343markup, pre (and Code) are the only ones that allow multiple newlines. The
344markup above will generate:
345
346[pre
347
348Some *preformatted* text Some *preformatted* text
349
350 Some *preformatted* text Some *preformatted* text
351
352 Some *preformatted* text Some *preformatted* text
353
354]
355
356Notice that unlike Code, phrase markup such as font style is still permitted
357inside =pre= blocks.
358
359[endsect] [/preformatted]
360
361[#quickbook.ref.blockquote]
362[section:blockquote Blockquote]
363
364[pre
365'''[:sometext...]'''
366]
367
368[:Indents the paragraph. This applies to one paragraph only.]
369
370[endsect] [/blockquote]
371
372[#quickbook.ref.admonitions]
373[section:admonitions Admonitions]
374
375```
376[note This is a note]
377[tip This is a tip]
378[important This is important]
379[caution This is a caution]
380[warning This is a warning]
381```
382
383generates __docbook__ admonitions:
384
385[note This is a note]
386[tip This is a tip]
387[important This is important]
388[caution This is a caution]
389[warning This is a warning]
390
391These are the only admonitions supported by __docbook__. So,
392for example [^\[information This is some information\]] is unlikely
393to produce the desired effect.
394
395[endsect] [/admonitions]
396
397[#quickbook.ref.headings]
398[section:headings Headings]
399
400```
401[h1 Heading 1]
402[h2 Heading 2]
403[h3 Heading 3]
404[h4 Heading 4]
405[h5 Heading 5]
406[h6 Heading 6]
407```
408
409[h1 Heading 1]
410[h2 Heading 2]
411[h3 Heading 3]
412[h4 Heading 4]
413[h5 Heading 5]
414[h6 Heading 6]
415
416You can specify an id for a heading:
417
418```
419[h1:heading_id A heading to link to]
420```
421
422To link to it, you'll need to include the enclosing section's id:
423
424```
425[link document_id.section_id.heading_id The link text]
426```
427
428Although you can preceed a heading by an [link quickbook.ref.anchors anchor]
429if you wish to use a location independent link.
430
431If a heading doesn't have an id, one will be automatically generated
432with a normalized name with
433[^name="document_id.section_id.normalized_header_text"] (i.e. valid
434characters are =a-z=, =A-Z=, =0-9= and =_=. All non-valid characters are
435converted to underscore and all upper-case are converted to lower-case.
436For example: Heading 1 in section Section 2 will be normalized to
437[^section_2.heading_1]). You can use:
438
439```
440[link document_id.section_id.normalized_header_text The link text]
441```
442
443to link to them. See __anchor_links__ and __section__ for more info.
444
445[note Specifying heading ids is a quickbook 1.6 feature, earlier
446 versions don't support them.]
447
448[endsect] [/headings]
449
450[#quickbook.ref.generic_heading]
451[section:generic_heading Generic Heading]
452
453In cases when you don't want to care about the heading level (1 to 6), you
454can use the /Generic Heading/:
455
456```
457[heading Heading]
458```
459
460The /Generic Heading/ assumes the level, plus one, of the innermost section
461where it is placed. For example, if it is placed in the outermost section,
462then, it assumes /h2/.
463
464Headings are often used as an alternative to sections. It is used
465particularly if you do not want to start a new section. In many cases,
466however, headings in a particular section is just flat. Example:
467
468```
469[section A]
470[h2 X]
471[h2:link_id Y]
472[h2 Z]
473[endsect]
474```
475
476Here we use h2 assuming that section A is the outermost level. If it is
477placed in an inner level, you'll have to use h3, h4, etc. depending on
478where the section is. In general, it is the section level plus one. It is
479rather tedious, however, to scan the section level everytime. If you
480rewrite the example above as shown below, this will be automatic:
481
482```
483[section A]
484[heading X]
485[heading Y]
486[heading Z]
487[endsect]
488```
489
490They work well regardless where you place them. You can rearrange sections
491at will without any extra work to ensure correct heading levels. In fact,
492with /section/ and /heading/, you have all you need. /h1/../h6/ becomes
493redundant. /h1/../h6/ might be deprecated in the future.
494
495[endsect] [/generic_heading]
496
497[#quickbook.ref.macros]
498[section:macros Macros]
499
500```
501[def macro_identifier some text]
502```
503
504When a macro is defined, the identifier replaces the text anywhere in the
505file, in paragraphs, in markups, etc. macro_identifier is a string of non-
506white space characters except '\]'. A macro may not follow an alphabetic
507character or the underscore. The replacement text can be any phrase (even
508marked up). Example:
509
510```
511[def sf_logo [$http://sourceforge.net/sflogo.php?group_id=28447&amp;type=1]]
512sf_logo
513```
514
515Now everywhere the sf_logo is placed, the picture will be inlined.
516
517[def sf_logo [$http://sourceforge.net/sflogo.php?group_id=28447&type=1]]
518sf_logo
519
520[tip It's a good idea to use macro identifiers that are distinguishable.
521For instance, in this document, macro identifiers have two leading and
522trailing underscores (e.g. [^\__spirit__]). The reason is to avoid
523unwanted macro replacement.]
524
525Links (URLS) and images are good candidates for macros. *1*) They tend to
526change a lot. It is a good idea to place all links and images in one place near the top
527to make it easy to make changes. *2*) The syntax is not pretty. It's easier to read and
528write, e.g. [^\__spirit__] than `[@http://spirit.sourceforge.net Spirit]`.
529
530Some more examples:
531
532```
533[def ``\:-)`` [$theme/smiley.png]]
534[def ``\__spirit__`` [@http://spirit.sourceforge.net Spirit]]
535```
536
537(See __images__ and __links__)
538
539Invoking these macros:
540
541```
542Hi ``\__spirit__`` ``\:-)``
543```
544
545will generate this:
546
547Hi __spirit__ :-)
548
549[endsect] [/macros]
550
551[#quickbook.ref.predefined_macros]
552[section:predefined_macros Predefined Macros]
553
554Quickbook has some predefined macros that you can already use.
555
556[table Predefined Macros
557 [[Macro] [Meaning] [Example]]
558 [[[^\__DATE__]] [Today's date] [__DATE__]]
559 [[[^\__TIME__]] [The current time] [__TIME__]]
560 [[[^\__FILENAME__]][Quickbook source filename] [__FILENAME__]]
561]
562
563[endsect] [/predefined_macros]
564
565[#quickbook.ref.templates]
566[section:templates Templates]
567
568Templates provide a more versatile text substitution mechanism. Templates
569come in handy when you need to create parameterizable, multi-line,
570boilerplate text that you specify once and expand many times. Templates
571accept one or more arguments. These arguments act like place-holders for
572text replacement. Unlike simple macros, which are limited to phrase level
573markup, templates can contain block level markup (e.g. paragraphs, code
574blocks and tables).
575
576Example template:
577
578```
579[template person[name age what]
580
581Hi, my name is [name]. I am [age] years old. I am a [what].
582
583]
584```
585
586[template person[name age what]
587
588Hi, my name is [name]. I am [age] years old. I am a [what].
589
590]
591
592[#quickbook.ref.template_identifier]
593[heading Template Identifier]
594
595Template identifiers can either consist of:
596
597* An initial alphabetic character or the underscore, followed by
598 zero or more alphanumeric characters or the underscore. This is
599 similar to your typical C/C++ identifier.
600* A single character punctuation (a non-alphanumeric printable character)
601
602[heading Formal Template Arguments]
603
604Template formal arguments are identifiers consisting of an initial
605alphabetic character or the underscore, followed by zero or more
606alphanumeric characters or the underscore. This is similar to your typical
607C/C++ identifier.
608
609A template formal argument temporarily hides a template of the same name at
610the point where the [link quickbook.ref.template_expansion
611template is expanded]. Note that the body of the [^person] template above
612refers to [^name] [^age] and [^what] as [^\[name\]] [^\[age\]] and
613[^\[what\]]. [^name] [^age] and [^what] are actually templates that exist
614in the duration of the template call.
615
616[heading Template Body]
617
618The template body can be just about any QuickBook block or phrase. There
619are actually two forms. Templates may be phrase or block level. Phrase
620templates are of the form:
621
622```
623[template sample[arg1 arg2...argN] replacement text... ]
624```
625
626Block templates are of the form:
627
628```
629[template sample[arg1 arg2...argN]
630replacement text...
631]
632```
633
634The basic rule is as follows: if a newline immediately follows the argument
635list, then it is a block template, otherwise, it is a phrase template.
636Phrase templates are typically expanded as part of phrases. Like macros,
637block level elements are not allowed in phrase templates.
638
639[heading Template Expansion]
640
641You expand a template this way:
642
643```
644[template_identifier arg1..arg2..arg3]
645```
646
647At template expansion, you supply the actual arguments. The template will
648be expanded with your supplied arguments. Example:
649
650```
651[person James Bond..39..Spy]
652[person Santa Clause..87..Big Red Fatso]
653```
654
655Which will expand to:
656
657[person James Bond..39..Spy]
658[person Santa Clause..87..Big Red Fatso]
659
660[caution A word of caution: Templates are recursive. A template can call
661another template or even itself, directly or indirectly. There are no
662control structures in QuickBook (yet) so this will always mean infinite
663recursion. QuickBook can detect this situation and report an error if
664recursion exceeds a certain limit.]
665
666Each actual argument can be a word, a text fragment or just about any [link
667quickbook.syntax.phrase QuickBook phrase]. Arguments are separated by the
668double dot [^".."] and terminated by the close parenthesis.
669
670Note that templates and template parameters can't be expanded
671everywhere, only where text is interpreted as a phrase. So they can't be
672expanded in places such as table titles and link's urls. If you want to
673use a template to generate a link based of the template parameter, you
674can't use a normal link and will need to use escaped docbook instead.
675Example:
676
677[teletype]
678```
679[template boost_ticket[key] '''<ulink url="https://svn.boost.org/trac/boost/ticket/'''[key]'''">#'''[key]'''</ulink>''']
680
681[boost_ticket 2035]
682```
683
684will expand to:
685
686[template boost_ticket[key] '''<ulink url="https://svn.boost.org/trac/boost/ticket/'''[key]'''">#'''[key]'''</ulink>''']
687
688[boost_ticket 2035]
689
690[caution Since quickbook doesn't understand the context where the
691parameter is being used, it will interpret it as quickbook markup, so
692when writing a template like this, you'll need to escape any meaningful
693punctuation.]
694
695[heading Nullary Templates]
696
697Nullary templates look and act like simple macros. Example:
698
699```
700[template alpha[]&apos;&apos;&apos;&amp;#945;&apos;&apos;&apos;]
701[template beta[]&apos;&apos;&apos;&amp;#946;&apos;&apos;&apos;]
702```
703
704[template alpha[]'''&#945;''']
705[template beta[]'''&#946;''']
706
707Expanding:
708
709```Some squigles...[*[alpha][beta]]```
710
711We have:
712
713Some squiggles...[*[alpha][beta]]
714
715The difference with macros are
716
717* The explicit [link quickbook.ref.template_expansion
718 template expansion syntax]. This is an advantage because, now, we don't
719 have to use obscure naming conventions like double underscores (e.g.
720 \_\_alpha\_\_) to avoid unwanted
721 macro replacement.
722* The template is expanded at the point where it is invoked. A macro is
723 expanded immediately at its point of declaration. This is subtle and
724 can cause a slight difference in behavior especially if you refer to
725 other macros and templates in the body.
726
727The empty brackets after the template identifier ([^alpha\[\]]) indicates no
728arguments. If the template body does not look like a template argument list, we
729can elide the empty brackets. Example:
730
731```
732[template aristotle_quote Aristotle: [*['Education is the best provision
733for the journey to old age.]]]
734```
735
736[template aristotle_quote\ Aristotle: [*['Education is the best provision
737for the journey to old age.]]]
738
739Expanding:
740
741```
742Here's a quote from [aristotle_quote].
743```
744
745We have:
746
747Here's a quote from [aristotle_quote].
748
749The disadvantage is that you can't avoid the space between the template
750identifier, `aristotle_quote`, and the template body "Aristotle...". This space
751will be part of the template body. If that space is unwanted, use empty
752brackets or use the space escape: "`\ `". Example:
753
754```
755[template tag\ _tag]
756```
757
758[template tag\ _tag]
759
760Then expanding:
761
762```
763`struct` x[tag];
764```
765
766We have:
767
768`struct` x[tag];
769
770You have a couple of ways to do it. I personally prefer the explicit empty
771brackets, though.
772
773[heading Simple Arguments]
774
775As mentioned, arguments are separated by the double dot [^".."]. Alternatively,
776if the double dot isn't used and more than one argument is expected, QuickBook
777uses whitespace to separate the arguments, following this logic:
778
779* Break the last argument into two, at the first space found ([^'', '\\n',
780 \\t' or '\\r']).
781* Repeat until there are enough arguments or if there are no more spaces
782 found (in which case, an error is reported).
783
784For example:
785
786```
787[template simple[a b c d] [a][b][c][d]]
788[simple w x y z]
789```
790
791will produce:
792
793[template simple[a b c d] [a][b][c][d]]
794[simple w x y z]
795
796"w x y z" is initially treated as a single argument because we didn't
797supply any [^".."] separators. However, since [^simple] expects 4
798arguments, "w x y z" is broken down iteratively (applying the logic above)
799until we have "w", "x", "y" and "z".
800
801QuickBook only tries to get the arguments it needs. For example:
802
803```
804[simple w x y z trail]
805```
806
807will produce:
808
809[simple w x y z trail]
810
811The arguments being: "w", "x", "y" and "z trail".
812
813[caution The behavior described here is for QuickBook 1.5. In older versions you
814could use both the double dot and whitespace as separators in the same template
815call. If your document is marked up as an older version, it will use the old
816behavior, which is described in the
817[@http://www.boost.org/doc/libs/1_40_0/doc/html/quickbook/syntax.html#quickbook.syntax.block.templates.simple_arguments
818QuickBook 1.4 documentation].]
819
820[heading Punctuation Templates]
821
822With templates, one of our objectives is to allow us to rewrite QuickBook
823in QuickBook (as a qbk library). For that to happen, we need to accommodate
824single character punctuation templates which are fairly common in
825QuickBook. You might have noticed that single character punctuations are
826allowed as [link quickbook.ref.template_identifier
827template identifiers]. Example:
828
829```
830[template ![bar] <hey>[bar]</hey>]
831```
832
833Now, expanding this:
834
835```
836[!baz]
837```
838
839We will have:
840
841[pre
842<hey>baz</hey>
843]
844
845[endsect] [/templates]
846
847[#quickbook.ref.blurbs]
848[section:blurbs Blurbs]
849
850```
851[blurb ``\:-)`` [*An eye catching advertisement or note...]
852
853 __spirit__ is an object-oriented recursive-descent parser generator framework
854 implemented using template meta-programming techniques. Expression templates
855 allow us to approximate the syntax of Extended Backus-Normal Form (EBNF)
856 completely in C++.
857]
858```
859
860will generate this:
861
862[blurb :-) [*An eye catching advertisement or note...]
863
864 __spirit__ is an object-oriented recursive-descent parser generator
865 framework implemented using template meta-programming techniques. Expression
866 templates allow us to approximate the syntax of Extended Backus-Normal Form
867 (EBNF) completely in C++.
868]
869
870[note Prefer [link quickbook.ref.admonitions admonitions] wherever
871appropriate.]
872
873[endsect] [/blurbs]
874
875[#quickbook.ref.tables]
876[section:tables Tables]
877
878```
879[table:id A Simple Table
880 [[Heading 1] [Heading 2] [Heading 3]]
881 [[R0-C0] [R0-C1] [R0-C2]]
882 [[R1-C0] [R1-C1] [R1-C2]]
883 [[R2-C0] [R2-C1] [R2-C2]]
884]
885```
886
887will generate:
888
889[table:id A Simple Table
890 [[Heading 1] [Heading 2] [Heading 3]]
891 [[R0-C0] [R0-C1] [R0-C2]]
892 [[R1-C0] [R1-C1] [R1-C2]]
893 [[R2-C0] [R2-C1] [R2-C2]]
894]
895
896The table title is optional. The first row of the table is automatically
897treated as the table header; that is, it is wrapped in [^<thead>...</thead>]
898XML tags. Note that unlike the original QuickDoc, the columns are nested in
899[cells... ].
900
901Giving tables an id is a new feature for quickbook 1.5 onwards. As with
902sections, the id is optional. If the table has a title but no id, an id will
903be generated from the title. The table above can be linked to using:
904
905```
906[link quickbook.syntax.block.tables.id link to table]
907```
908
909which will generate:
910
911[link quickbook.syntax.block.tables.id link to table]
912
913The syntax is free-format and allows big cells to be formatted
914nicely. Example:
915
916```
917[table Table with fat cells
918 [[Heading 1] [Heading 2]]
919 [
920 [Row 0, Col 0: a small cell]
921 [
922 Row 0, Col 1: a big fat cell with paragraphs
923
924 Boost provides free peer-reviewed portable C++ source libraries.
925
926 We emphasize libraries that work well with the C++ Standard Library.
927 Boost libraries are intended to be widely useful, and usable across
928 a broad spectrum of applications. The Boost license encourages both
929 commercial and non-commercial use.
930 ]
931 ]
932 [
933 [Row 1, Col 0: a small cell]
934 [Row 1, Col 1: a small cell]
935 ]
936]
937```
938
939and thus:
940
941[table Table with fat cells
942 [[Heading 1] [Heading 2]]
943 [
944 [Row 0, Col 0: a small cell]
945 [
946 Row 0, Col 1: a big fat cell with paragraphs
947
948 Boost provides free peer-reviewed portable C++ source libraries.
949 [/ <-- There's a space here. Don't remove. This is intentional, for testing]
950 We emphasize libraries that work well with the C++ Standard Library.
951 Boost libraries are intended to be widely useful, and usable across
952 a broad spectrum of applications. The Boost license encourages both
953 commercial and non-commercial use.
954 ]
955 ]
956 [
957 [Row 1, Col 0: a small cell]
958 [Row 1, Col 1: a small cell]
959 ]
960]
961
962Here's how to have preformatted blocks of code in a table cell:
963
964```
965[table Table with code
966 [[Comment] [Code]]
967 [
968 [My first program]
969 [``\`\`\ ``
970 #include <iostream>
971
972 int main()
973 {
974 std::cout << "Hello, World!" << std::endl;
975 return 0;
976 }
977 ``\`\`\ ``]
978 ]
979]
980```
981
982[table Table with code
983 [[Comment] [Code]]
984 [
985 [My first program]
986 [``
987 #include <iostream>
988
989 int main()
990 {
991 std::cout << "Hello, World!" << std::endl;
992 return 0;
993 }
994 ``]
995 ]
996]
997
998[endsect] [/tables]
999
1000[#quickbook.ref.variable_lists]
1001[section:variable_lists Variable Lists]
1002
1003```
1004[variablelist A Variable List
1005 [[term 1] [The definition of term 1]]
1006 [[term 2] [The definition of term 2]]
1007 [[term 3] [
1008 The definition of term 3.
1009
1010 Definitions may contain paragraphs.
1011 ]]
1012]
1013```
1014
1015will generate:
1016
1017[variablelist A Variable List
1018 [[term 1] [The definition of term 1]]
1019 [[term 2] [The definition of term 2]]
1020 [[term 3] [
1021 The definition of term 3.
1022
1023 Definitions may contain paragraphs.
1024 ]]
1025]
1026
1027The rules for variable lists are the same as for tables, except that
1028only 2 "columns" are allowed. The first column contains the terms, and
1029the second column contains the definitions. Those familiar with HTML
1030will recognize this as a "definition list".
1031
1032[endsect] [/variable_lists]
1033
1034[#quickbook.ref.include]
1035[section:include Include]
1036
1037You can include one QuickBook file from another. The syntax is simply:
1038
1039```
1040[include someother.qbk]
1041```
1042
1043In quickbook 1.6 and later, if the included file has a
1044[link quickbook.ref.docinfo docinfo block] then it will create a nested
1045document. This will be processed as a standalone document, although any macros
1046or templates from the enclosing file will still be defined.
1047
1048Otherwise the included file will be processed as if it had been cut and pasted
1049into the current document, with the following exceptions:
1050
1051* The '''__FILENAME__''' predefined macro will reflect the name of the
1052 file currently being processed.
1053* Any macros or templates defined in the included file are scoped to that file,
1054 i.e. they are not added to the enclosing file.
1055
1056[note In quickbook 1.5 and earlier templates weren't scoped in included files.
1057If you want to use templates or macros from a file in quickbook 1.6,
1058use [link quickbook.ref.import import] instead.]
1059
1060The [^\[include\]] directive lets you specify a document id to use for the
1061included file. You can specify the id like this:
1062
1063```
1064[include:someid someother.qbk]
1065```
1066
1067All auto-generated anchors will use the document id as a unique prefix. So
1068for instance, if there is a top section in someother.qbk named "Intro", the
1069named anchor for that section will be "someid.intro", and you can link to
1070it with [^\[link someid.intro The Intro\]].
1071
1072If the included file has a docinfo block, an id specified in an [^\[include\]]
1073directive will overwrite it.
1074
1075You can also include C, C++ and python source files. This will include any
1076quickbook blocks in the file that aren't inside of named code snippets. See
1077the [link quickbook.ref.import Import section] for syntax details. For example,
1078say you included this file:
1079
1080 /**
1081 * Hello world example
1082 */
1083
1084 // In this comment, the backtick indicates that this is a
1085 // quickbook source block that will be included.
1086
1087 /*`
1088 First include the appropriate header: [hello_includes]
1089 Then write your main function: [hello_main]
1090 */
1091
1092 // This defines a code snippet, the syntax is
1093 // described in the import section. It's available
1094 // in the whole of this source file, not just after
1095 // its definition.
1096
1097 //[hello_includes
1098 #include <iostream>
1099 //]
1100
1101 //[hello_main
1102 int main() {
1103 std::cout << "Hello, trivial example" << std::endl;
1104 }
1105 //]
1106
1107It will generate:
1108
1109 First include the appropriate header:
1110
1111 #include <iostream>
1112
1113 Then write your main function:
1114
1115 int main() {
1116 std::cout << "Hello, trivial example" << std::endl;
1117 }
1118
1119[endsect] [/include]
1120
1121[#quickbook.ref.import]
1122[section:import Import]
1123
1124In quickbook 1.6 and later if you wish to use a template, macro or code
1125snippet from a file, you need to import it. This will not include any
1126of the content from that file, but will pull templates, macros and code
1127snippets into the current file's scope.
1128
1129With quickbook files, this allows you to create template and macro
1130libraries. For python (indicated by the `.py` extension), C or
1131C++ files this allows you to include code snippets from source files,
1132so that your code examples can be kept up to date and fully tested.
1133
1134[/ Old justification text, might move this into a new section:
1135
1136When documenting code, you'd surely need to present code from actual source
1137files. While it is possible to copy some code and paste them in your QuickBook
1138file, doing so is error prone and the extracted code in the documentation tends
1139to get out of sync with the actual code as the code evolves. The problem, as
1140always, is that once documentation is written, the tendency is for the docs to
1141languish in the archives without maintenance.
1142
1143QuickBook's import facility provides a nice solution.
1144]
1145
1146[heading Example]
1147
1148You can effortlessly import code snippets from source code into your QuickBook.
1149The following illustrates how this is done:
1150
1151```
1152[import ../test/stub.cpp]
1153[foo]
1154[bar]
1155```
1156
1157The first line:
1158
1159```
1160[import ../test/stub.cpp]
1161```
1162
1163collects specially marked-up code snippets from
1164[@boost:/tools/quickbook/test/stub.cpp stub.cpp]
1165and places them in your QuickBook file as virtual templates. Each of the
1166specially marked-up code snippets has a name (e.g. `foo` and `bar` in the
1167example above). This shall be the template identifier for that particular code
1168snippet. The second and third line above does the actual template expansion:
1169
1170```
1171[foo]
1172[bar]
1173```
1174
1175And the result is:
1176
1177[import ../test/stub.cpp]
1178[foo]
1179[bar]
1180
1181[heading Code Snippet Markup]
1182
1183Note how the code snippets in [@boost:/tools/quickbook/test/stub.cpp stub.cpp]
1184get marked up. We use distinguishable comments following the form:
1185
1186 //[id
1187 some code here
1188 //]
1189
1190The first comment line above initiates a named code-snippet. This prefix will
1191not be visible in quickbook. The entire code-snippet in between `//[id` and
1192`//]` will be inserted as a template in quickbook with name ['/id/]. The comment
1193`//]` ends a code-snippet This too will not be visible in quickbook.
1194
1195[heading Special Comments]
1196
1197Special comments of the form:
1198
1199 //` some [*quickbook] markup here
1200
1201and:
1202
1203 /*` some [*quickbook] markup here */
1204
1205will be parsed by QuickBook. This can contain quickbook /blocks/ (e.g. sections,
1206paragraphs, tables, etc). In the first case, the initial slash-slash, tick and
1207white-space shall be ignored. In the second, the initial slash-star-tick and the
1208final star-slash shall be ignored.
1209
1210Special comments of the form:
1211
1212 /*<- this C++ comment will be ignored ->*/
1213
1214or
1215
1216 /*<-*/ "this c++ code will be ignored" /*->*/
1217
1218or
1219
1220 //<-
1221 private:
1222 int some_member;
1223 //->
1224
1225can be used to inhibit code from passing through to quickbook. All text between
1226the delimeters will simply be ignored.
1227
1228Comments of this form:
1229
1230 //=int main() {}
1231
1232or
1233
1234 /*=foo()*/
1235
1236will be displayed as code that isn't in comments. This allows you to
1237include some code in the snippet but not actually use it when
1238compiling your example.
1239
1240[heading Callouts]
1241
1242Special comments of the form:
1243
1244 /*< some [*quickbook] markup here >*/
1245
1246will be regarded as callouts. These will be collected, numbered and
1247rendered as a "callout bug" (a small icon with a number). After the
1248whole snippet is parsed, the callout list is generated. See
1249[@http://www.docbook.org/tdg/en/html/callout.html Callouts] for details.
1250Example:
1251
1252[foo_bar]
1253
1254This is the actual code:
1255
1256 //[ foo_bar
1257 std::string foo_bar() /*< The /Mythical/ FooBar.
1258 See [@http://en.wikipedia.org/wiki/Foobar Foobar for details] >*/
1259 {
1260 return "foo-bar"; /*< return 'em, foo-bar man! >*/
1261 }
1262 //]
1263
1264The callouts bugs are placed exactly where the special callout comment
1265is situated. It can be anywhere in the code. The bugs can be rather
1266obtrusive, however. They get in the way of the clarity of the code.
1267Another special callout comment style is available:
1268
1269 /*<< some [*quickbook] markup here >>*/
1270
1271This is the line-oriented version of the callout. With this, the "bug"
1272is placed at the very left of the code block, away from the actual code.
1273By placing it at the far left, the code is rendered un-obscured.
1274Example:
1275
1276[class_]
1277
1278See the actual code here:
1279[@boost:/tools/quickbook/test/stub.cpp tools/quickbook/test/stub.cpp]
1280
1281[endsect] [/import]
1282
1283[#quickbook.ref.block]
1284[section:block Plain blocks]
1285
1286`block` is a plain block element, that doesn't wrap its contents
1287in any docbook or boostbook tags. This can be useful when using
1288escaped docbook block tags, such as:
1289
1290 [template chapter[title]
1291 [block'''<chapter><title>'''[title]'''</title>''']
1292 ]
1293
1294 [template chapterend
1295 [block'''</chapter>''']
1296 ]
1297
1298 [chapter An example chapter]
1299
1300 Content
1301
1302 [chapterend]
1303
1304Without the `block` element, the `chapter` and `chapterend` templates
1305would be wrapped in paragraph tags.
1306
1307[note In this example, the template body has to start with a newline so that
1308the template will be interpreted in block mode.]
1309
1310[endsect] [/block]