handler ¤
This module implements a handler for the C language.
Classes:
-
CHandler
–The C handler class.
-
CodeDoc
–A parsed C source file.
-
Comment
–A comment extracted from the source code.
-
DocFunc
–A parsed function.
-
DocGlobalVar
–A parsed global variable.
-
DocMacro
–A parsed macro.
-
DocType
–A parsed typedef.
-
Docstring
–A parsed docstring.
-
FuncParam
–A parameter in a function signature.
-
InOut
–Enumeration for parameter direction.
-
Macro
–A macro extracted from the source code.
-
Param
–A parameter in a function signature.
-
SupportsQualsAndType
–A protocol for types that can have qualifiers and a type.
-
TypeDecl
–Enumeration for type declarations.
-
TypeRef
–A reference to a type in C.
Functions:
-
ast_to_decl
–Convert a pycparser AST node to a TypeRef.
-
desc
–Get the description from a docstring.
-
extract_comments
–Extract comments from the source code.
-
extract_macros
–Extract macros from the source code.
-
get_handler
–Simply return an instance of
CHandler
. -
lookup_type_html
–Lookup a type and return an HTML representation.
-
parse_docstring
–Parse a docstring.
-
tp_ref_to_str
–Convert a TypeRef to a string.
-
typedef_to_str
–Convert a typedef to a string.
CHandler ¤
Bases: BaseHandler
The C handler class.
Methods:
-
collect
–Collect data given an identifier and selection configuration.
-
render
–Render a template using provided data and configuration options.
-
update_env
–Update the Jinja environment with any custom settings/filters/options for this handler.
Attributes:
-
default_config
(dict
) –The default configuration options.
-
domain
(str
) –The cross-documentation domain/language for this handler.
-
enable_inventory
(bool
) –Whether this handler is interested in enabling the creation of the
objects.inv
Sphinx inventory file. -
fallback_config
(dict
) –The configuration used to collect item during autorefs fallback.
-
fallback_theme
–The theme to fallback to.
-
name
(str
) –The handler's name.
default_config class-attribute
¤
default_config: dict = {
"show_root_heading": False,
"show_root_toc_entry": True,
"show_symbol_type_heading": True,
"show_symbol_type_toc_entry": True,
"heading_level": 2,
}
The default configuration options.
Option | Type | Description | Default |
---|---|---|---|
show_root_heading | bool | Show the heading of the object at the root of the documentation tree. | False |
show_root_toc_entry | bool | If the root heading is not shown, at least add a ToC entry for it. | True |
heading_level | int | The initial heading level to use. | 2 |
domain class-attribute
instance-attribute
¤
domain: str = 'c'
The cross-documentation domain/language for this handler.
enable_inventory class-attribute
instance-attribute
¤
enable_inventory: bool = False
Whether this handler is interested in enabling the creation of the objects.inv
Sphinx inventory file.
fallback_config class-attribute
¤
fallback_config: dict = {'fallback': True}
The configuration used to collect item during autorefs fallback.
fallback_theme class-attribute
instance-attribute
¤
fallback_theme = 'material'
The theme to fallback to.
collect ¤
collect(
identifier: str, config: MutableMapping[str, Any]
) -> CollectorItem
Collect data given an identifier and selection configuration.
In the implementation, you typically call a subprocess that returns JSON, and load that JSON again into a Python dictionary for example, though the implementation is completely free.
Parameters:
-
identifier
(str
) –An identifier that was found in a markdown document for which to collect data. For example, in Python, it would be 'mkdocstrings.handlers' to collect documentation about the handlers module. It can be anything that you can feed to the tool of your choice.
-
config
(MutableMapping[str, Any]
) –All configuration options for this handler either defined globally in
mkdocs.yml
or locally overridden in an identifier block by the user.
Returns:
-
CollectorItem
–Anything you want, as long as you can feed it to the
render
method.
render ¤
Render a template using provided data and configuration options.
Parameters:
-
data
(CodeDoc
) –The data to render that was collected above in
collect()
. -
config
(Mapping[str, Any]
) –All configuration options for this handler either defined globally in
mkdocs.yml
or locally overridden in an identifier block by the user.
Returns:
-
str
–The rendered template as HTML.
update_env ¤
update_env(md: Markdown, config: dict) -> None
Update the Jinja environment with any custom settings/filters/options for this handler.
Parameters:
-
md
(Markdown
) –The Markdown instance. Useful to add functions able to convert Markdown into the environment filters.
-
config
(dict
) –Configuration options for
mkdocs
andmkdocstrings
, read frommkdocs.yml
. See the source code of mkdocstrings.plugin.MkdocstringsPlugin.on_config to see what's in this dictionary.
CodeDoc dataclass
¤
CodeDoc(
macros: list[DocMacro],
functions: list[DocFunc],
global_vars: list[DocGlobalVar],
typedefs: dict[str, DocType],
)
A parsed C source file.
Comment dataclass
¤
A comment extracted from the source code.
DocFunc dataclass
¤
A parsed function.
DocGlobalVar dataclass
¤
A parsed global variable.
DocMacro dataclass
¤
A parsed macro.
DocType dataclass
¤
A parsed typedef.
Docstring dataclass
¤
A parsed docstring.
TypeRef dataclass
¤
TypeRef(
name: TypeRef | str,
decl: TypeDecl,
quals: list[str],
params: list[TypeRef] | None = None,
)
A reference to a type in C.
ast_to_decl ¤
ast_to_decl(
node: SupportsQualsAndType, types: dict[str, DocType]
) -> TypeRef
Convert a pycparser AST node to a TypeRef.
desc ¤
extract_comments ¤
extract_macros ¤
get_handler ¤
get_handler(
theme: str,
custom_templates: str | None = None,
config_file_path: str | None = None,
**config: Any
) -> CHandler
Simply return an instance of CHandler
.
Parameters:
-
theme
(str
) –The theme to use when rendering contents.
-
custom_templates
(str | None
, default:None
) –Directory containing custom templates.
-
config_file_path
(str | None
, default:None
) –The MkDocs configuration file path.
-
**config
(Any
, default:{}
) –Configuration passed to the handler.
Returns:
-
CHandler
–An instance of the handler.