If a document contains more than one type of source code then the source mode may be changed dynamically as the document is processed. All QuickBook documents are initially in C++ mode by default, though an alternative initial value may be set in the Document section.
To change the source mode, use the [source-mode]
markup,
where source-mode
is one of the supported modes. For
example, this:
Python's [python] `import` is rather like C++'s [c++] `#include`. A C++ comment `// looks like this` whereas a Python comment [python] `# looks like this`.
will generate:
Python's import
is rather
like C++'s #include
.
A C++ comment // looks like this
whereas a Python comment #looks like this
.
Quickbook 1.7 introduced the !
element which can be used to
set the source mode of the following element:
[teletype] Example in C++: [!c++] `int main() {}`, example with no highlighting: `int main() {}`.
will generate:
Example in C++: int main() {}
, example
with no highlighting: int main() {}
.
In order to change the source mode for a whole paragraph, put the !
element on a separate line before the paragraph:
[!c++] `int main() {}` is highlighted as C++, as is `//example`. [!c++] `int main() {}` is also highlighted as C++, but `//example` isn't.
generates:
int main() {}
is
highlighted as C++, as is //example
.
int main() {}
is
also highlighted as C++, but //example
isn't.
The !
element can also be used to set the source mode for
blocks and sections. For example:
[!python] [section:python Section in which all code samples use python] [/...] [endsect:python] [!c++] [section:cpp Section in which all code samples use C++] [/...] [endsect:cpp]
Or to set the source mode for a table:
[!teletype] [table [[code][meaning]] [[`+`][addition]] ]
Table 11.2. Supported Source Modes
Mode |
Source Mode Markup |
---|---|
C++ |
|
Python |
|
Plain Text |
|
Note | |
---|---|
The source mode strings are lowercase. |