Generators
MrDocs uses a generator to convert the extracted symbols into documentation.
MrDocs supports multiple output formats that can be specified via the generate
option:
The generate
option can be used to specify the output format:
# ...
generate: adoc
# ...
Three output formats are supported:
Format | Description |
---|---|
|
AsciiDoc format. |
|
HTML format. |
|
XML format. |
The corpus of symbols is provided to the generator responsible for converting these symbols into the desired output format.
The xml
generator is used as an intermediary format for other tools or for testing purposes.
Users can write their own tools to process the XML output and generate custom documentation.
The adoc
and html
generators use templates to generate the documentation.
These templates can be customized to change the output format and style.
Asciidoc is a text-based format that is easy to read and write. It can also be converted to other formats such as HTML and Markdown.
HTML can be generated directly with the html
format.
Choosing the Right Generator
The scatter plot below illustrates the available output formats for MrDocs, along with hypothetical solutions, in terms of redundancy and convenience.
-
Redundancy: The amount of duplicated or unstructured information in the output format. Lower redundancy is generally preferred for post-processing, while higher redundancy can allow the output to use formats that are easier to use directly.
-
Convenience: Reflects how readily the output format can be used without requiring additional tools or steps.
Although Clang can generate and print an Abstract Syntax Tree (AST) directly for a Translation Unit (TU), it is not the most convenient format for generating documentation:
-
It does not provide the AST in a format that’s easy to process.
-
Equivalent symbols can be redeclared multiple times in the same translation unit and across translation units.
-
The documentation for equivalent symbols also needs to be unified.
The scatter plot shows the following output formats supported by MrDocs:
-
XML: Aggregates all symbols and their documentation in a format that is straightforward to process. It’s suitable for advanced use cases involving custom post-processing tools.
-
Asciidoc: Similar to HTML in convenience, Asciidoc files can be easily converted to HTML and multiple other formats with backends.
-
HTML: Generates output that is directly usable in a variety of contexts, such as web pages or documentation systems.
The Asciidoc and HTML generators also support Custom Templates to change the output format and style. This forms another possibility in the trade-off between redundancy and convenience.
The best trade-offs, represented by the line passing through the generators, indicate the optimal solutions in terms of redundancy and convenience. Solutions on this line balance these goals effectively. Dots in the background represent other potential formats that do not lie on the front of best trade-offs, as they fail to optimize either redundancy or convenience compared to the available generators.
Generator Templates
MrDocs attempts to support various alternatives for customizing the output format and style without complex workflows to post-process XML output.
The adoc
and html
generators use Handlebars templates.
These templates can be customized to change the output format and style of the documentation.
The templates used to generate the documentation are located in the share/mrdocs/addons/generator
directory.
Users can create a copy of these files and provide their own addons
directory via the addons
option in the configuration file or via the command line.
addons: /path/to/custom/addons
Each symbol goes through a main layout template in the <addons>/generator/<generator>/layouts/single-symbol.<generator>.hbs
directory.
This template is a simple entry point that renders the partial relative to the symbol kind.
The partials are located in the <addons>/generator/<generator>/partials
directory.
It typically contains the following files and subdirectories:
-
symbol
: A generic partial for rendering symbols. -
location
: Partials for rendering location objects. -
symbol
: Partials for rendering Symbol Objects. -
template
: Partials for rendering Template Info Objects. -
type
: Partials for rendering Type Info Objects. -
markup
: partials for rendering markup elements such as lists, tables, and code blocks, in the output format.
Please refer to the Document Object Model Reference for more information on each type of object.
Partials common to all generators are available in the <addons>/generator/common/partials
directory.
The common partials are loaded before the generator-specific partials, which can override any common partials.
The multipage generator renders the layout multiple times as separate pages for each symbol. The single-page generator renders the layout multiple times and concatenates the results in a single page.
Each time the generator encounters a symbol, it renders the layout template with the symbol data as the Handlebars context.
The layout template can include other partial templates to render the symbol data. These partials are available in the <addons>/generator/<generator>/partials
directory.
The Document Object Model (DOM) for each symbol includes all information about the symbol.One advantage of custom templates over post-processing XML files is the ability to access symbols as a graph.If symbol A
refers to symbol B
, some properties of symbol B
are likely to be required in the documentation of A
.All templates and generators can access a reference to B
by searching the symbol tree or simply by accessing the elements A
refers to.All references to other symbols are resolved in the templates.
Document Object Model Reference
The Document Object Model (DOM) is a tree structure that represents the symbols extracted from the source code.The DOM is used by the generator to render the documentation.
Top-Level Fields
The top-level object in the DOM is the context for a template.The top-level object has the following properties:
Property | Type | Description |
---|---|---|
|
The symbol being rendered. |
|
|
The configuration object. |
Symbol
The Symbol
object represents a symbol extracted from the source code.The symbol being rendered is available in the symbol
object in the Handlebars context.The symbol object has the following properties:
Property | Type | Description |
---|---|---|
|
|
A unique identifier for the symbol. |
|
|
The nonqualified name of the symbol. |
|
|
The kind of symbol. (e.g., |
|
|
The access level of the symbol. (e.g., |
|
|
Whether the symbol was implicitly extracted as a dependency. |
|
The namespaces of the symbol. |
|
|
The parent namespace of the symbol. |
|
|
|
The documentation for the symbol. |
Handlebars generators extend each symbol with the following fields:
Property | Type | Description |
---|---|---|
|
|
The URL of the symbol. If the documentation is a single page, this is the anchor link to the symbol starting with |
|
|
The anchor link to the symbol. This is used for section IDs in the documentation. |
The Symbol
object has additional properties based on the kind of symbol.
The following table lists the additional properties for symbols that contain information about their scope (such as Namespaces and Classes):
Property | Type | Description |
---|---|---|
|
The members of that scope (e.g., member functions, namespace symbols). |
|
|
Same as |
Symbol objects that contain information about the location include the following properties:
Property | Type | Description |
---|---|---|
|
The location of the symbol in the source code. |
When the symbol kind is namespace
, the symbol object has the following additional properties:
Property | Type | Description |
---|---|---|
|
The interface of the namespace. |
|
|
The using directives of the namespace. |
When the symbol kind is record
(e.g., class
, struct
, union
), the symbol object has the following additional properties:
Property | Type | Description |
---|---|---|
|
|
The type of record (e.g., |
|
|
The default access level of the record members (e.g., |
|
|
Whether the record is a typedef. |
|
The base classes of the record. |
|
|
The interface of the record. |
|
|
The template information of the record. |
When the symbol kind is enum
, the symbol object has the following additional properties:
Property | Type | Description |
---|---|---|
|
The type information of the enum. |
|
|
|
Whether the enum is scoped. |
When the symbol kind is function
, the symbol object has the following additional properties:
Property | Type | Description |
---|---|---|
|
|
Whether the function is variadic. |
|
|
Whether the function is virtual. |
|
|
Whether the function is virtual as written. |
|
|
Whether the function is pure. |
|
|
Whether the function is defaulted. |
|
|
Whether the function is explicitly defaulted. |
|
|
Whether the function is deleted. |
|
|
Whether the function is deleted as written. |
|
|
Whether the function is noreturn. |
|
|
Whether the function has the override attribute. |
|
|
Whether the function has a trailing return type. |
|
|
Whether the function is const. |
|
|
Whether the function is volatile. |
|
|
Whether the function is final. |
|
|
Whether the function is nodiscard. |
|
|
Whether the function is an explicit object member function. |
|
|
The constexpr kind of the function (e.g., |
|
|
The storage class of the function (e.g., |
|
|
The reference qualifier of the function (e.g., |
|
|
The function class (e.g., |
|
The parameters of the function. |
|
|
The return type of the function. |
|
|
The template information of the function. |
|
|
|
The overloaded operator of the function. |
|
|
The exception specification of the function. |
|
|
The explicit specification of the function. |
|
|
The |
When the symbol kind is typedef
, the symbol object has the following additional properties:
Property | Type | Description |
---|---|---|
|
The type information of the typedef. |
|
|
The template information of the typedef. |
|
|
|
Whether the typedef is a |
When the symbol kind is variable
, the symbol object has the following additional properties:
Property | Type | Description |
---|---|---|
|
The type information of the variable. |
|
|
The template information of the variable. |
|
|
|
The constexpr kind of the variable (e.g., |
|
|
The storage class of the variable (e.g., |
|
|
Whether the variable is |
|
|
Whether the variable is thread-local. |
|
|
The initializer of the variable. |
When the symbol kind is field
(i.e. non-static data members), the symbol object has the following additional properties:
Property | Type | Description |
---|---|---|
|
The type information of the field. |
|
|
|
The default value of the field. |
|
|
Whether the field is maybe unused. |
|
|
Whether the field is deprecated. |
|
|
Whether the field is a variant. |
|
|
Whether the field is mutable. |
|
|
Whether the field is a bitfield. |
|
|
|
|
|
The width of the bitfield. |
When the symbol kind is friend
, the symbol object has the following additional properties:
Property | Type | Description |
---|---|---|
|
|
The name of the friend symbol or type. |
|
The friend symbol. |
|
|
The friend type. |
When the symbol kind is alias
, the symbol object has the following additional properties:
Property | Type | Description |
---|---|---|
|
The aliased symbol. |
When the symbol kind is using
, the symbol object has the following additional properties:
Property | Type | Description |
---|---|---|
|
|
The class of the using declaration (e.g., |
|
The symbols being used. |
|
|
The qualifier of the using declaration. |
When the symbol kind is enumerator
, the symbol object has the following additional properties:
Property | Type | Description |
---|---|---|
|
|
The initializer of the enumerator. |
When the symbol kind is guide
, the symbol object has the following additional properties:
Property | Type | Description |
---|---|---|
|
The parameters of the guide. |
|
|
The deduced type of the guide. |
|
|
The template information of the guide. |
|
|
|
The explicit specification of the guide. |
When the symbol kind is concept
, the symbol object has the following additional properties:
Property | Type | Description |
---|---|---|
|
The template information of the concept. |
|
|
|
The constraint of the concept. |
Source Info Fields
The Source Info
object represents the location of the symbol in the source code.
The source info object has the following properties:
Property | Type | Description |
---|---|---|
|
Location where the entity was defined. |
|
|
Locations where the entity was declared. |
Tranche Object Fields
The Tranche
object represents the symbols in a scope (e.g., namespace).
The tranche object has the following properties:
Property | Type | Description |
---|---|---|
(symbol kind in plural form: e.g., |
The symbols of that kind in the scope. |
|
|
The types in the scope. |
|
|
The static functions in the scope. |
|
|
The overloads in the scope. |
|
|
The static overloads in the scope. |
Interface Object Fields
The Interface
object represents the interface of a record (e.g., class, struct, union).
The interface object has the following properties:
Property | Type | Description |
---|---|---|
|
The public interface of the record. |
|
|
The protected interface of the record. |
|
|
The private interface of the record. |
Base Info Fields
The Base Info
object represents a base class of a record.
The base info object has the following properties:
Property | Type | Description |
---|---|---|
|
|
The access level of the base class. |
|
|
Whether the base class is virtual. |
|
The type information of the base class. |
Template Info Fields
The Template Info
object represents the template information of a record, function, or typedef.
The template info object has the following properties:
Property | Type | Description |
---|---|---|
|
|
The kind of template (e.g., |
|
The primary template. |
|
|
The template parameters. |
|
|
The template arguments. |
|
|
|
The |
Type Info Fields
The Type Info
object represents the type information of a symbol.
The type info object has the following properties:
Property | Type | Description |
---|---|---|
|
|
The kind of type (e.g., |
|
|
Whether the type is a pack expansion. |
|
|
The name of the type. |
|
|
The operand of the type. |
|
|
The keyword of the type. |
|
|
The constraint of the type. |
|
|
The cv qualifier of the type (e.g., |
|
The parent type of the type. |
|
|
The pointee type of the type. |
|
|
The element type of the type. |
|
|
|
The bounds value of the type. |
|
|
The bounds expression of the type. |
|
The return type of the type. |
|
|
The parameter types of the type. |
|
|
|
The exception specification of the type. |
|
|
The reference qualifier of the type. |
|
|
Whether the type is variadic. |
Param Fields
The Param
object represents the parameter of a function.
The param object has the following properties:
Property | Type | Description |
---|---|---|
|
|
The name of the parameter. |
|
The type information of the parameter. |
|
|
|
The default value of the parameter. |
Name Info Fields
The Name Info
object represents the name of a symbol.
The name info object has the following properties:
Property | Type | Description |
---|---|---|
|
|
The name of the symbol. |
|
|
The unique identifier of the symbol. |
|
The template arguments of the symbol. |
|
|
|
The prefix of the symbol. |
Location Fields
The Location
object represents the location of a symbol in the source code.
The location object has the following properties:
Property | Type | Description |
---|---|---|
|
|
The path of the source file. |
|
|
The filename of the source file. |
|
|
The line number of the symbol. |
|
|
The kind of file (e.g., |
|
|
Whether the symbol is documented. |
TParam Fields
The TParam
object represents a template parameter of a record, function, or typedef.
The tparam object has the following properties:
Property | Type | Description |
---|---|---|
|
|
The kind of template parameter (e.g., |
|
|
The name of the template parameter. |
|
|
Whether the template parameter is a pack expansion. |
|
|
The default value of the template parameter. |
|
|
The key kind of the template parameter. |
|
|
The constraint of the template parameter. |
|
The type information of the template parameter. |
|
|
The template parameters of the template parameter. |
Targ Fields
The Targ
object represents a template argument of a record, function, or typedef.
The targ object has the following properties:
Property | Type | Description |
---|---|---|
|
|
The kind of template argument (e.g., |
|
|
Whether the template argument is a pack expansion. |
|
The type information of the template argument. |
|
|
|
The value of the template argument. |
|
|
The name of the template argument. |
|
The template information of the template argument. |
Config Fields
The Config
object represents the configuration object.
It includes all values provided to MrDocs in the configuration file or via the command line.
Please refer to the configuration file reference for more information.