2 Copyright 2002,2004,2006 Joel de Guzman, Eric Niebler
3 Copyright 2010-2011 Daniel James
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)
10 [chapter Block Level Elements
12 [compatibility-mode 1.5]
13 [id quickbook.syntax.block]
14 [source-mode teletype]
17 [#quickbook.ref.xinclude]
18 [section:xinclude xinclude]
20 You can include another XML file with:
26 This is useful when file.xml has been generated by Doxygen and contains your
29 =xinclude= paths are normally used unchanged in the generated documentation,
30 which will not work if you wish them to be relative to the current quickbook
31 file. Quickbook can add a =xml:base= attribute to the boostbook documentation
32 to specify where =xinclude= files should be found. For example, if you wish
33 them to be relative to the current quickbook file:
35 [article Article with xincludes
42 Now the xinclude should work if =file.xml= is in the same directory as the
43 quickbook file. Although it might not work if you distribute the generated
44 files (as their relative directories can change).
46 Say the article is generated in a sub-directory, by running something like:
48 quickbook article.qbk --output-file=output/article.xml
50 This will generate a boostbook root tag:
52 <article id="article_with_xincludes"
53 last-revision="$Date: 2013/08/20 08:26:48 $"
55 xmlns:xi="http://www.w3.org/2001/XInclude">
57 Because =xml:base= is set to =..=, the xml processor will know to look in
58 the parent directory to find =file.xml=, which it comes across the
63 [#quickbook.ref.paragraphs]
64 [section:paragraphs Paragraphs]
66 Paragraphs start left-flushed and are terminated by two or more newlines. No
67 markup is needed for paragraphs. QuickBook automatically detects paragraphs from
68 the 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]
71 This is a new paragraph...
73 [endsect] [/paragraphs]
75 [#quickbook.ref.lists]
77 [#quickbook.ref.ordered_lists]
78 [section:ordered_lists Ordered lists]
92 [endsect] [/ordered_lists]
93 [#quickbook.ref.list_hierarchies]
94 [section:list_hierarchies List Hierarchies]
96 List hierarchies are supported. Example:
126 [endsect] [/list_hierarchies]
127 [#quickbook.ref.long_list_lines]
128 [section:long_list_lines Long List Lines]
130 Long lines will be wrapped appropriately. Example:
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.
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.
150 [endsect] [/long_list_lines]
151 [#quickbook.ref.unordered_lists]
152 [section:unordered_lists Unordered lists]
166 [endsect] [/unordered_lists]
167 [#quickbook.ref.mixed_lists]
168 [section:mixed_lists Mixed lists]
170 Mixed lists (ordered and unordered) are supported. Example:
224 [endsect] [/mixed_lists]
226 [#quickbook.ref.list_tags]
227 [section:list_tags Explicit list tags]
229 Sometimes the wiki-style list markup can be tricky to use, especially
230 if you wish to include more complicated markup with the list. So in
231 quickbook 1.6, an alternative way to mark up lists introduced:
233 [ordered_list [item1][item2]]
242 [itemized_list [item1][item2]]
249 [endsect] [/list_tags]
252 [#quickbook.ref.code]
255 Preformatted code starts with a space or a tab. The code will be
256 syntax highlighted according to the current __source_mode__:
265 std::cout << "Hello, World\n";
273 def cookForHtml(text):
274 '''"Cooks" the input text for HTML.'''
276 return cgi.escape(text)
280 Macros that are already defined are expanded in source code. Example:
283 [def __array__ [@http://www.boost.org/doc/html/array/reference.html array]]
284 [def __boost__ [@http://www.boost.org/libs/libraries.htm boost]]
286 using __boost__::__array__;
291 [def __array__ [@http://www.boost.org/doc/html/array/reference.html array]]
292 [def __boost__ [@http://www.boost.org/libs/libraries.htm boost]]
294 using __boost__::__array__;
298 [#quickbook.ref.escape_back]
299 [section:escape_back Escaping Back To QuickBook]
301 Inside code, code blocks and inline code, QuickBook does not allow any
302 markup to avoid conflicts with the target syntax (e.g. c++). In case you
303 need to switch back to QuickBook markup inside code, you can do so using a
304 language specific /escape-back/ delimiter. In C++ and Python, the delimiter
305 is the double tick (back-quote): "\`\`" and "\`\`". Example:
308 void ``[@http://en.wikipedia.org/wiki/Foo#Foo.2C_Bar_and_Baz foo]``()
315 void ``[@http://en.wikipedia.org/wiki/Foo#Foo.2C_Bar_and_Baz foo]``()
319 When escaping from code to QuickBook, only phrase level markups are
320 allowed. Block level markups like lists, tables etc. are not allowed.
322 [endsect] [/escaping_back_to_quickbook]
324 [#quickbook.ref.preformatted]
325 [section:preformatted Preformatted]
327 Sometimes, you don't want some preformatted text to be parsed as source code. In such
328 cases, use the [^\[pre ... \]] markup block.
333 Some *preformatted* text Some *preformatted* text
335 Some *preformatted* text Some *preformatted* text
337 Some *preformatted* text Some *preformatted* text
342 Spaces, tabs and newlines are rendered as-is. Unlike all quickbook block level
343 markup, pre (and Code) are the only ones that allow multiple newlines. The
344 markup above will generate:
348 Some *preformatted* text Some *preformatted* text
350 Some *preformatted* text Some *preformatted* text
352 Some *preformatted* text Some *preformatted* text
356 Notice that unlike Code, phrase markup such as font style is still permitted
359 [endsect] [/preformatted]
361 [#quickbook.ref.blockquote]
362 [section:blockquote Blockquote]
368 [:Indents the paragraph. This applies to one paragraph only.]
370 [endsect] [/blockquote]
372 [#quickbook.ref.admonitions]
373 [section:admonitions Admonitions]
376 [note This is a note]
378 [important This is important]
379 [caution This is a caution]
380 [warning This is a warning]
383 generates __docbook__ admonitions:
385 [note This is a note]
387 [important This is important]
388 [caution This is a caution]
389 [warning This is a warning]
391 These are the only admonitions supported by __docbook__. So,
392 for example [^\[information This is some information\]] is unlikely
393 to produce the desired effect.
395 [endsect] [/admonitions]
397 [#quickbook.ref.headings]
398 [section:headings Headings]
416 You can specify an id for a heading:
419 [h1:heading_id A heading to link to]
422 To link to it, you'll need to include the enclosing section's id:
425 [link document_id.section_id.heading_id The link text]
428 Although you can preceed a heading by an [link quickbook.ref.anchors anchor]
429 if you wish to use a location independent link.
431 If a heading doesn't have an id, one will be automatically generated
432 with a normalized name with
433 [^name="document_id.section_id.normalized_header_text"] (i.e. valid
434 characters are =a-z=, =A-Z=, =0-9= and =_=. All non-valid characters are
435 converted to underscore and all upper-case are converted to lower-case.
436 For example: Heading 1 in section Section 2 will be normalized to
437 [^section_2.heading_1]). You can use:
440 [link document_id.section_id.normalized_header_text The link text]
443 to link to them. See __anchor_links__ and __section__ for more info.
445 [note Specifying heading ids is a quickbook 1.6 feature, earlier
446 versions don't support them.]
448 [endsect] [/headings]
450 [#quickbook.ref.generic_heading]
451 [section:generic_heading Generic Heading]
453 In cases when you don't want to care about the heading level (1 to 6), you
454 can use the /Generic Heading/:
460 The /Generic Heading/ assumes the level, plus one, of the innermost section
461 where it is placed. For example, if it is placed in the outermost section,
462 then, it assumes /h2/.
464 Headings are often used as an alternative to sections. It is used
465 particularly if you do not want to start a new section. In many cases,
466 however, headings in a particular section is just flat. Example:
476 Here we use h2 assuming that section A is the outermost level. If it is
477 placed in an inner level, you'll have to use h3, h4, etc. depending on
478 where the section is. In general, it is the section level plus one. It is
479 rather tedious, however, to scan the section level everytime. If you
480 rewrite the example above as shown below, this will be automatic:
490 They work well regardless where you place them. You can rearrange sections
491 at will without any extra work to ensure correct heading levels. In fact,
492 with /section/ and /heading/, you have all you need. /h1/../h6/ becomes
493 redundant. /h1/../h6/ might be deprecated in the future.
495 [endsect] [/generic_heading]
497 [#quickbook.ref.macros]
498 [section:macros Macros]
501 [def macro_identifier some text]
504 When a macro is defined, the identifier replaces the text anywhere in the
505 file, in paragraphs, in markups, etc. macro_identifier is a string of non-
506 white space characters except '\]'. A macro may not follow an alphabetic
507 character or the underscore. The replacement text can be any phrase (even
511 [def sf_logo [$http://sourceforge.net/sflogo.php?group_id=28447&type=1]]
515 Now everywhere the sf_logo is placed, the picture will be inlined.
517 [def sf_logo [$http://sourceforge.net/sflogo.php?group_id=28447&type=1]]
520 [tip It's a good idea to use macro identifiers that are distinguishable.
521 For instance, in this document, macro identifiers have two leading and
522 trailing underscores (e.g. [^\__spirit__]). The reason is to avoid
523 unwanted macro replacement.]
525 Links (URLS) and images are good candidates for macros. *1*) They tend to
526 change a lot. It is a good idea to place all links and images in one place near the top
527 to make it easy to make changes. *2*) The syntax is not pretty. It's easier to read and
528 write, e.g. [^\__spirit__] than `[@http://spirit.sourceforge.net Spirit]`.
533 [def ``\:-)`` [$theme/smiley.png]]
534 [def ``\__spirit__`` [@http://spirit.sourceforge.net Spirit]]
537 (See __images__ and __links__)
539 Invoking these macros:
542 Hi ``\__spirit__`` ``\:-)``
551 [#quickbook.ref.predefined_macros]
552 [section:predefined_macros Predefined Macros]
554 Quickbook has some predefined macros that you can already use.
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__]]
563 [endsect] [/predefined_macros]
565 [#quickbook.ref.templates]
566 [section:templates Templates]
568 Templates provide a more versatile text substitution mechanism. Templates
569 come in handy when you need to create parameterizable, multi-line,
570 boilerplate text that you specify once and expand many times. Templates
571 accept one or more arguments. These arguments act like place-holders for
572 text replacement. Unlike simple macros, which are limited to phrase level
573 markup, templates can contain block level markup (e.g. paragraphs, code
579 [template person[name age what]
581 Hi, my name is [name]. I am [age] years old. I am a [what].
586 [template person[name age what]
588 Hi, my name is [name]. I am [age] years old. I am a [what].
592 [#quickbook.ref.template_identifier]
593 [heading Template Identifier]
595 Template identifiers can either consist of:
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)
602 [heading Formal Template Arguments]
604 Template formal arguments are identifiers consisting of an initial
605 alphabetic character or the underscore, followed by zero or more
606 alphanumeric characters or the underscore. This is similar to your typical
609 A template formal argument temporarily hides a template of the same name at
610 the point where the [link quickbook.ref.template_expansion
611 template is expanded]. Note that the body of the [^person] template above
612 refers to [^name] [^age] and [^what] as [^\[name\]] [^\[age\]] and
613 [^\[what\]]. [^name] [^age] and [^what] are actually templates that exist
614 in the duration of the template call.
616 [heading Template Body]
618 The template body can be just about any QuickBook block or phrase. There
619 are actually two forms. Templates may be phrase or block level. Phrase
620 templates are of the form:
623 [template sample[arg1 arg2...argN] replacement text... ]
626 Block templates are of the form:
629 [template sample[arg1 arg2...argN]
634 The basic rule is as follows: if a newline immediately follows the argument
635 list, then it is a block template, otherwise, it is a phrase template.
636 Phrase templates are typically expanded as part of phrases. Like macros,
637 block level elements are not allowed in phrase templates.
639 [heading Template Expansion]
641 You expand a template this way:
644 [template_identifier arg1..arg2..arg3]
647 At template expansion, you supply the actual arguments. The template will
648 be expanded with your supplied arguments. Example:
651 [person James Bond..39..Spy]
652 [person Santa Clause..87..Big Red Fatso]
655 Which will expand to:
657 [person James Bond..39..Spy]
658 [person Santa Clause..87..Big Red Fatso]
660 [caution A word of caution: Templates are recursive. A template can call
661 another template or even itself, directly or indirectly. There are no
662 control structures in QuickBook (yet) so this will always mean infinite
663 recursion. QuickBook can detect this situation and report an error if
664 recursion exceeds a certain limit.]
666 Each actual argument can be a word, a text fragment or just about any [link
667 quickbook.syntax.phrase QuickBook phrase]. Arguments are separated by the
668 double dot [^".."] and terminated by the close parenthesis.
670 Note that templates and template parameters can't be expanded
671 everywhere, only where text is interpreted as a phrase. So they can't be
672 expanded in places such as table titles and link's urls. If you want to
673 use a template to generate a link based of the template parameter, you
674 can't use a normal link and will need to use escaped docbook instead.
679 [template boost_ticket[key] '''<ulink url="https://svn.boost.org/trac/boost/ticket/'''[key]'''">#'''[key]'''</ulink>''']
686 [template boost_ticket[key] '''<ulink url="https://svn.boost.org/trac/boost/ticket/'''[key]'''">#'''[key]'''</ulink>''']
690 [caution Since quickbook doesn't understand the context where the
691 parameter is being used, it will interpret it as quickbook markup, so
692 when writing a template like this, you'll need to escape any meaningful
695 [heading Nullary Templates]
697 Nullary templates look and act like simple macros. Example:
700 [template alpha[]'''&#945;''']
701 [template beta[]'''&#946;''']
704 [template alpha[]'''α''']
705 [template beta[]'''β''']
709 ```Some squigles...[*[alpha][beta]]```
713 Some squiggles...[*[alpha][beta]]
715 The difference with macros are
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
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.
727 The empty brackets after the template identifier ([^alpha\[\]]) indicates no
728 arguments. If the template body does not look like a template argument list, we
729 can elide the empty brackets. Example:
732 [template aristotle_quote Aristotle: [*['Education is the best provision
733 for the journey to old age.]]]
736 [template aristotle_quote\ Aristotle: [*['Education is the best provision
737 for the journey to old age.]]]
742 Here's a quote from [aristotle_quote].
747 Here's a quote from [aristotle_quote].
749 The disadvantage is that you can't avoid the space between the template
750 identifier, `aristotle_quote`, and the template body "Aristotle...". This space
751 will be part of the template body. If that space is unwanted, use empty
752 brackets or use the space escape: "`\ `". Example:
770 You have a couple of ways to do it. I personally prefer the explicit empty
773 [heading Simple Arguments]
775 As mentioned, arguments are separated by the double dot [^".."]. Alternatively,
776 if the double dot isn't used and more than one argument is expected, QuickBook
777 uses whitespace to separate the arguments, following this logic:
779 * Break the last argument into two, at the first space found ([^'', '\\n',
781 * Repeat until there are enough arguments or if there are no more spaces
782 found (in which case, an error is reported).
787 [template simple[a b c d] [a][b][c][d]]
793 [template simple[a b c d] [a][b][c][d]]
796 "w x y z" is initially treated as a single argument because we didn't
797 supply any [^".."] separators. However, since [^simple] expects 4
798 arguments, "w x y z" is broken down iteratively (applying the logic above)
799 until we have "w", "x", "y" and "z".
801 QuickBook only tries to get the arguments it needs. For example:
804 [simple w x y z trail]
809 [simple w x y z trail]
811 The arguments being: "w", "x", "y" and "z trail".
813 [caution The behavior described here is for QuickBook 1.5. In older versions you
814 could use both the double dot and whitespace as separators in the same template
815 call. If your document is marked up as an older version, it will use the old
816 behavior, 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
818 QuickBook 1.4 documentation].]
820 [heading Punctuation Templates]
822 With templates, one of our objectives is to allow us to rewrite QuickBook
823 in QuickBook (as a qbk library). For that to happen, we need to accommodate
824 single character punctuation templates which are fairly common in
825 QuickBook. You might have noticed that single character punctuations are
826 allowed as [link quickbook.ref.template_identifier
827 template identifiers]. Example:
830 [template ![bar] <hey>[bar]</hey>]
845 [endsect] [/templates]
847 [#quickbook.ref.blurbs]
848 [section:blurbs Blurbs]
851 [blurb ``\:-)`` [*An eye catching advertisement or note...]
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)
862 [blurb :-) [*An eye catching advertisement or note...]
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++.
870 [note Prefer [link quickbook.ref.admonitions admonitions] wherever
875 [#quickbook.ref.tables]
876 [section:tables Tables]
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]]
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]]
896 The table title is optional. The first row of the table is automatically
897 treated as the table header; that is, it is wrapped in [^<thead>...</thead>]
898 XML tags. Note that unlike the original QuickDoc, the columns are nested in
901 Giving tables an id is a new feature for quickbook 1.5 onwards. As with
902 sections, the id is optional. If the table has a title but no id, an id will
903 be generated from the title. The table above can be linked to using:
906 [link quickbook.syntax.block.tables.id link to table]
911 [link quickbook.syntax.block.tables.id link to table]
913 The syntax is free-format and allows big cells to be formatted
917 [table Table with fat cells
918 [[Heading 1] [Heading 2]]
920 [Row 0, Col 0: a small cell]
922 Row 0, Col 1: a big fat cell with paragraphs
924 Boost provides free peer-reviewed portable C++ source libraries.
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.
933 [Row 1, Col 0: a small cell]
934 [Row 1, Col 1: a small cell]
941 [table Table with fat cells
942 [[Heading 1] [Heading 2]]
944 [Row 0, Col 0: a small cell]
946 Row 0, Col 1: a big fat cell with paragraphs
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.
957 [Row 1, Col 0: a small cell]
958 [Row 1, Col 1: a small cell]
962 Here's how to have preformatted blocks of code in a table cell:
965 [table Table with code
974 std::cout << "Hello, World!" << std::endl;
982 [table Table with code
991 std::cout << "Hello, World!" << std::endl;
1000 [#quickbook.ref.variable_lists]
1001 [section:variable_lists Variable Lists]
1004 [variablelist A Variable List
1005 [[term 1] [The definition of term 1]]
1006 [[term 2] [The definition of term 2]]
1008 The definition of term 3.
1010 Definitions may contain paragraphs.
1017 [variablelist A Variable List
1018 [[term 1] [The definition of term 1]]
1019 [[term 2] [The definition of term 2]]
1021 The definition of term 3.
1023 Definitions may contain paragraphs.
1027 The rules for variable lists are the same as for tables, except that
1028 only 2 "columns" are allowed. The first column contains the terms, and
1029 the second column contains the definitions. Those familiar with HTML
1030 will recognize this as a "definition list".
1032 [endsect] [/variable_lists]
1034 [#quickbook.ref.include]
1035 [section:include Include]
1037 You can include one QuickBook file from another. The syntax is simply:
1040 [include someother.qbk]
1043 In quickbook 1.6 and later, if the included file has a
1044 [link quickbook.ref.docinfo docinfo block] then it will create a nested
1045 document. This will be processed as a standalone document, although any macros
1046 or templates from the enclosing file will still be defined.
1048 Otherwise the included file will be processed as if it had been cut and pasted
1049 into the current document, with the following exceptions:
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.
1056 [note In quickbook 1.5 and earlier templates weren't scoped in included files.
1057 If you want to use templates or macros from a file in quickbook 1.6,
1058 use [link quickbook.ref.import import] instead.]
1060 The [^\[include\]] directive lets you specify a document id to use for the
1061 included file. You can specify the id like this:
1064 [include:someid someother.qbk]
1067 All auto-generated anchors will use the document id as a unique prefix. So
1068 for instance, if there is a top section in someother.qbk named "Intro", the
1069 named anchor for that section will be "someid.intro", and you can link to
1070 it with [^\[link someid.intro The Intro\]].
1072 If the included file has a docinfo block, an id specified in an [^\[include\]]
1073 directive will overwrite it.
1075 You can also include C, C++ and python source files. This will include any
1076 quickbook blocks in the file that aren't inside of named code snippets. See
1077 the [link quickbook.ref.import Import section] for syntax details. For example,
1078 say you included this file:
1081 * Hello world example
1084 // In this comment, the backtick indicates that this is a
1085 // quickbook source block that will be included.
1088 First include the appropriate header: [hello_includes]
1089 Then write your main function: [hello_main]
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
1103 std::cout << "Hello, trivial example" << std::endl;
1109 First include the appropriate header:
1113 Then write your main function:
1116 std::cout << "Hello, trivial example" << std::endl;
1119 [endsect] [/include]
1121 [#quickbook.ref.import]
1122 [section:import Import]
1124 In quickbook 1.6 and later if you wish to use a template, macro or code
1125 snippet from a file, you need to import it. This will not include any
1126 of the content from that file, but will pull templates, macros and code
1127 snippets into the current file's scope.
1129 With quickbook files, this allows you to create template and macro
1130 libraries. For python (indicated by the `.py` extension), C or
1131 C++ files this allows you to include code snippets from source files,
1132 so that your code examples can be kept up to date and fully tested.
1134 [/ Old justification text, might move this into a new section:
1136 When documenting code, you'd surely need to present code from actual source
1137 files. While it is possible to copy some code and paste them in your QuickBook
1138 file, doing so is error prone and the extracted code in the documentation tends
1139 to get out of sync with the actual code as the code evolves. The problem, as
1140 always, is that once documentation is written, the tendency is for the docs to
1141 languish in the archives without maintenance.
1143 QuickBook's import facility provides a nice solution.
1148 You can effortlessly import code snippets from source code into your QuickBook.
1149 The following illustrates how this is done:
1152 [import ../test/stub.cpp]
1160 [import ../test/stub.cpp]
1163 collects specially marked-up code snippets from
1164 [@boost:/tools/quickbook/test/stub.cpp stub.cpp]
1165 and places them in your QuickBook file as virtual templates. Each of the
1166 specially marked-up code snippets has a name (e.g. `foo` and `bar` in the
1167 example above). This shall be the template identifier for that particular code
1168 snippet. The second and third line above does the actual template expansion:
1177 [import ../test/stub.cpp]
1181 [heading Code Snippet Markup]
1183 Note how the code snippets in [@boost:/tools/quickbook/test/stub.cpp stub.cpp]
1184 get marked up. We use distinguishable comments following the form:
1190 The first comment line above initiates a named code-snippet. This prefix will
1191 not 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.
1195 [heading Special Comments]
1197 Special comments of the form:
1199 //` some [*quickbook] markup here
1203 /*` some [*quickbook] markup here */
1205 will be parsed by QuickBook. This can contain quickbook /blocks/ (e.g. sections,
1206 paragraphs, tables, etc). In the first case, the initial slash-slash, tick and
1207 white-space shall be ignored. In the second, the initial slash-star-tick and the
1208 final star-slash shall be ignored.
1210 Special comments of the form:
1212 /*<- this C++ comment will be ignored ->*/
1216 /*<-*/ "this c++ code will be ignored" /*->*/
1225 can be used to inhibit code from passing through to quickbook. All text between
1226 the delimeters will simply be ignored.
1228 Comments of this form:
1236 will be displayed as code that isn't in comments. This allows you to
1237 include some code in the snippet but not actually use it when
1238 compiling your example.
1242 Special comments of the form:
1244 /*< some [*quickbook] markup here >*/
1246 will be regarded as callouts. These will be collected, numbered and
1247 rendered as a "callout bug" (a small icon with a number). After the
1248 whole snippet is parsed, the callout list is generated. See
1249 [@http://www.docbook.org/tdg/en/html/callout.html Callouts] for details.
1254 This is the actual code:
1257 std::string foo_bar() /*< The /Mythical/ FooBar.
1258 See [@http://en.wikipedia.org/wiki/Foobar Foobar for details] >*/
1260 return "foo-bar"; /*< return 'em, foo-bar man! >*/
1264 The callouts bugs are placed exactly where the special callout comment
1265 is situated. It can be anywhere in the code. The bugs can be rather
1266 obtrusive, however. They get in the way of the clarity of the code.
1267 Another special callout comment style is available:
1269 /*<< some [*quickbook] markup here >>*/
1271 This is the line-oriented version of the callout. With this, the "bug"
1272 is placed at the very left of the code block, away from the actual code.
1273 By placing it at the far left, the code is rendered un-obscured.
1278 See the actual code here:
1279 [@boost:/tools/quickbook/test/stub.cpp tools/quickbook/test/stub.cpp]
1283 [#quickbook.ref.block]
1284 [section:block Plain blocks]
1286 `block` is a plain block element, that doesn't wrap its contents
1287 in any docbook or boostbook tags. This can be useful when using
1288 escaped docbook block tags, such as:
1290 [template chapter[title]
1291 [block'''<chapter><title>'''[title]'''</title>''']
1294 [template chapterend
1295 [block'''</chapter>''']
1298 [chapter An example chapter]
1304 Without the `block` element, the `chapter` and `chapterend` templates
1305 would be wrapped in paragraph tags.
1307 [note In this example, the template body has to start with a newline so that
1308 the template will be interpreted in block mode.]