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