c Β€
C handler for mkdocstrings.
Classes:
-
CConfigβC handler configuration.
-
CHandlerβThe C handler class.
-
CInputConfigβC handler configuration.
-
CInputOptionsβAccepted input options.
-
COptionsβFinal options passed as template context.
-
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.
CConfig dataclass Β€
Bases: CInputConfig
C handler configuration.
Methods:
Attributes:
options class-attribute instance-attribute Β€
Global options in mkdocs.yml.
CHandler Β€
Bases: BaseHandler
The C handler class.
Parameters:
-
config(Mapping[str, Any]) βThe handler configuration.
-
base_dir(Path) βThe base directory of the project.
-
**kwargs(Any, default:{}) βArguments passed to the parent constructor.
Methods:
-
collectβCollect data given an identifier and selection configuration.
-
do_convert_markdownβRender Markdown text; for use inside templates.
-
do_headingβRender an HTML heading and register it for the table of contents. For use inside templates.
-
get_aliasesβReturn the possible aliases for a given identifier.
-
get_extended_templates_dirsβLoad template extensions for the given handler, return their templates directories.
-
get_headingsβReturn and clear the headings gathered so far.
-
get_inventory_urlsβReturn the URLs (and configuration options) of the inventory files to download.
-
get_optionsβCombine configuration options.
-
get_templates_dirβReturn the path to the handler's templates directory.
-
load_inventoryβYield items and their URLs from an inventory file streamed from
in_file. -
renderβRender a template using provided data and configuration options.
-
render_backlinksβRender backlinks.
-
teardownβTeardown the handler.
-
update_envβUpdate the Jinja environment with any custom settings/filters/options for this handler.
Attributes:
-
base_dirβThe base directory of the project.
-
configβThe handler configuration.
-
custom_templatesβThe path to custom templates.
-
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.invSphinx inventory file. -
envβThe Jinja environment.
-
extra_css(str) βExtra CSS.
-
fallback_config(dict) βFallback configuration when searching anchors for identifiers.
-
fallback_theme(str) βThe theme to fallback to.
-
global_optionsβThe global options for the handler.
-
md(Markdown) βThe Markdown instance.
-
mdxβThe Markdown extensions to use.
-
mdx_configβThe configuration for the Markdown extensions.
-
name(str) βThe handler's name.
-
outer_layer(bool) βWhether we're in the outer Markdown conversion layer.
-
themeβThe selected theme.
custom_templates instance-attribute Β€
custom_templates = custom_templates
The path to custom templates.
domain class-attribute Β€
domain: str = 'c'
The cross-documentation domain/language for this handler.
enable_inventory class-attribute Β€
enable_inventory: bool = False
Whether this handler is interested in enabling the creation of the objects.inv Sphinx inventory file.
env instance-attribute Β€
env = Environment(
autoescape=True,
loader=FileSystemLoader(paths),
auto_reload=False,
)
The Jinja environment.
fallback_config class-attribute Β€
fallback_config: dict = {}
Fallback configuration when searching anchors for identifiers.
global_options instance-attribute Β€
global_options = get('options', {})
The global options for the handler.
md property Β€
md: Markdown
mdx_config instance-attribute Β€
mdx_config = mdx_config
The configuration for the Markdown extensions.
collect Β€
collect(
identifier: str, options: COptions
) -> 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.
-
options(COptions) βAll configuration options for this handler either defined globally in
mkdocs.ymlor locally overridden in an identifier block by the user.
Returns:
-
CollectorItemβAnything you want, as long as you can feed it to the
rendermethod.
do_convert_markdown Β€
do_convert_markdown(
text: str,
heading_level: int,
html_id: str = "",
*,
strip_paragraph: bool = False,
autoref_hook: AutorefsHookInterface | None = None,
) -> Markup
Render Markdown text; for use inside templates.
Parameters:
-
text(str) βThe text to convert.
-
heading_level(int) βThe base heading level to start all Markdown headings from.
-
html_id(str, default:'') βThe HTML id of the element that's considered the parent of this element.
-
strip_paragraph(bool, default:False) βWhether to exclude the
<p>tag from around the whole output.
Returns:
-
MarkupβAn HTML string.
do_heading Β€
do_heading(
content: Markup,
heading_level: int,
*,
role: str | None = None,
hidden: bool = False,
toc_label: str | None = None,
**attributes: str,
) -> Markup
Render an HTML heading and register it for the table of contents. For use inside templates.
Parameters:
-
content(Markup) βThe HTML within the heading.
-
heading_level(int) βThe level of heading (e.g. 3 ->
h3). -
role(str | None, default:None) βAn optional role for the object bound to this heading.
-
hidden(bool, default:False) βIf True, only register it for the table of contents, don't render anything.
-
toc_label(str | None, default:None) βThe title to use in the table of contents ('data-toc-label' attribute).
-
**attributes(str, default:{}) βAny extra HTML attributes of the heading.
Returns:
-
MarkupβAn HTML string.
get_aliases Β€
get_extended_templates_dirs Β€
get_headings Β€
get_inventory_urls Β€
Return the URLs (and configuration options) of the inventory files to download.
get_options Β€
Combine configuration options.
get_templates_dir Β€
Return the path to the handler's templates directory.
Override to customize how the templates directory is found.
Parameters:
-
handler(str | None, default:None) βThe name of the handler to get the templates directory of.
Raises:
-
ModuleNotFoundErrorβWhen no such handler is installed.
-
FileNotFoundErrorβWhen the templates directory cannot be found.
Returns:
-
PathβThe templates directory path.
load_inventory classmethod Β€
load_inventory(
in_file: BinaryIO,
url: str,
base_url: str | None = None,
**kwargs: Any,
) -> Iterator[tuple[str, str]]
Yield items and their URLs from an inventory file streamed from in_file.
Parameters:
-
in_file(BinaryIO) βThe binary file-like object to read the inventory from.
-
url(str) βThe URL that this file is being streamed from (used to guess
base_url). -
base_url(str | None, default:None) βThe URL that this inventory's sub-paths are relative to.
-
**kwargs(Any, default:{}) βIgnore additional arguments passed from the config.
Yields:
render Β€
Render a template using provided data and configuration options.
Parameters:
-
data(CodeDoc) βThe data to render that was collected above in
collect(). -
options(COptions) βAll configuration options for this handler either defined globally in
mkdocs.ymlor locally overridden in an identifier block by the user.
Returns:
-
strβThe rendered template as HTML.
render_backlinks Β€
Render backlinks.
teardown Β€
teardown() -> None
Teardown the handler.
This method should be implemented to, for example, terminate a subprocess that was started when creating the handler instance.
update_env Β€
update_env(config: dict) -> None
Update the Jinja environment with any custom settings/filters/options for this handler.
Parameters:
-
config(dict) βConfiguration options for
mkdocsandmkdocstrings, read frommkdocs.yml. See the source code of mkdocstrings.MkdocstringsPlugin.on_config to see what's in this dictionary.
CInputConfig dataclass Β€
CInputConfig(
options: Annotated[
CInputOptions,
_Field(
description="Configuration options for collecting and rendering objects."
),
] = CInputOptions(),
)
C handler configuration.
Methods:
Attributes:
-
options(Annotated[CInputOptions, _Field(description='Configuration options for collecting and rendering objects.')]) βConfiguration options for collecting and rendering objects.
options class-attribute instance-attribute Β€
options: Annotated[
CInputOptions,
_Field(
description="Configuration options for collecting and rendering objects."
),
] = field(default_factory=CInputOptions)
Configuration options for collecting and rendering objects.
CInputOptions dataclass Β€
CInputOptions(
extra: Annotated[
dict[str, Any],
_Field(
group="general", description="Extra options."
),
] = dict(),
heading: Annotated[
str,
_Field(
group="headings",
description="A custom string to override the autogenerated heading of the root object.",
),
] = "",
heading_level: Annotated[
int,
_Field(
group="headings",
description="The initial heading level to use.",
),
] = 2,
show_symbol_type_heading: Annotated[
bool,
_Field(
group="headings",
description="Show the symbol type in headings (e.g. mod, class, meth, func and attr).",
),
] = False,
show_symbol_type_toc: Annotated[
bool,
_Field(
group="headings",
description="Show the symbol type in the Table of Contents (e.g. mod, class, methd, func and attr).",
),
] = False,
toc_label: Annotated[
str,
_Field(
group="headings",
description="A custom string to override the autogenerated toc label of the root object.",
),
] = "",
)
Accepted input options.
Methods:
Attributes:
-
extra(Annotated[dict[str, Any], _Field(group='general', description='Extra options.')]) βExtra options.
-
heading(Annotated[str, _Field(group='headings', description='A custom string to override the autogenerated heading of the root object.')]) βA custom string to override the autogenerated heading of the root object.
-
heading_level(Annotated[int, _Field(group='headings', description='The initial heading level to use.')]) βThe initial heading level to use.
-
show_symbol_type_heading(Annotated[bool, _Field(group='headings', description='Show the symbol type in headings (e.g. mod, class, meth, func and attr).')]) βShow the symbol type in headings (e.g. mod, class, meth, func and attr).
-
show_symbol_type_toc(Annotated[bool, _Field(group='headings', description='Show the symbol type in the Table of Contents (e.g. mod, class, methd, func and attr).')]) βShow the symbol type in the Table of Contents (e.g. mod, class, methd, func and attr).
-
toc_label(Annotated[str, _Field(group='headings', description='A custom string to override the autogenerated toc label of the root object.')]) βA custom string to override the autogenerated toc label of the root object.
extra class-attribute instance-attribute Β€
extra: Annotated[
dict[str, Any],
_Field(group="general", description="Extra options."),
] = field(default_factory=dict)
Extra options.
heading class-attribute instance-attribute Β€
heading: Annotated[
str,
_Field(
group="headings",
description="A custom string to override the autogenerated heading of the root object.",
),
] = ""
A custom string to override the autogenerated heading of the root object.
heading_level class-attribute instance-attribute Β€
heading_level: Annotated[
int,
_Field(
group="headings",
description="The initial heading level to use.",
),
] = 2
The initial heading level to use.
show_symbol_type_heading class-attribute instance-attribute Β€
show_symbol_type_heading: Annotated[
bool,
_Field(
group="headings",
description="Show the symbol type in headings (e.g. mod, class, meth, func and attr).",
),
] = False
Show the symbol type in headings (e.g. mod, class, meth, func and attr).
show_symbol_type_toc class-attribute instance-attribute Β€
show_symbol_type_toc: Annotated[
bool,
_Field(
group="headings",
description="Show the symbol type in the Table of Contents (e.g. mod, class, methd, func and attr).",
),
] = False
Show the symbol type in the Table of Contents (e.g. mod, class, methd, func and attr).
COptions dataclass Β€
COptions(
extra: Annotated[
dict[str, Any],
_Field(
group="general", description="Extra options."
),
] = dict(),
heading: Annotated[
str,
_Field(
group="headings",
description="A custom string to override the autogenerated heading of the root object.",
),
] = "",
heading_level: Annotated[
int,
_Field(
group="headings",
description="The initial heading level to use.",
),
] = 2,
show_symbol_type_heading: Annotated[
bool,
_Field(
group="headings",
description="Show the symbol type in headings (e.g. mod, class, meth, func and attr).",
),
] = False,
show_symbol_type_toc: Annotated[
bool,
_Field(
group="headings",
description="Show the symbol type in the Table of Contents (e.g. mod, class, methd, func and attr).",
),
] = False,
toc_label: Annotated[
str,
_Field(
group="headings",
description="A custom string to override the autogenerated toc label of the root object.",
),
] = "",
)
Bases: CInputOptions
Final options passed as template context.
Methods:
-
coerceβCreate an instance from a dictionary.
-
from_dataβCreate an instance from a dictionary.
Attributes:
-
extra(Annotated[dict[str, Any], _Field(group='general', description='Extra options.')]) βExtra options.
-
heading(Annotated[str, _Field(group='headings', description='A custom string to override the autogenerated heading of the root object.')]) βA custom string to override the autogenerated heading of the root object.
-
heading_level(Annotated[int, _Field(group='headings', description='The initial heading level to use.')]) βThe initial heading level to use.
-
show_symbol_type_heading(Annotated[bool, _Field(group='headings', description='Show the symbol type in headings (e.g. mod, class, meth, func and attr).')]) βShow the symbol type in headings (e.g. mod, class, meth, func and attr).
-
show_symbol_type_toc(Annotated[bool, _Field(group='headings', description='Show the symbol type in the Table of Contents (e.g. mod, class, methd, func and attr).')]) βShow the symbol type in the Table of Contents (e.g. mod, class, methd, func and attr).
-
toc_label(Annotated[str, _Field(group='headings', description='A custom string to override the autogenerated toc label of the root object.')]) βA custom string to override the autogenerated toc label of the root object.
extra class-attribute instance-attribute Β€
extra: Annotated[
dict[str, Any],
_Field(group="general", description="Extra options."),
] = field(default_factory=dict)
Extra options.
heading class-attribute instance-attribute Β€
heading: Annotated[
str,
_Field(
group="headings",
description="A custom string to override the autogenerated heading of the root object.",
),
] = ""
A custom string to override the autogenerated heading of the root object.
heading_level class-attribute instance-attribute Β€
heading_level: Annotated[
int,
_Field(
group="headings",
description="The initial heading level to use.",
),
] = 2
The initial heading level to use.
show_symbol_type_heading class-attribute instance-attribute Β€
show_symbol_type_heading: Annotated[
bool,
_Field(
group="headings",
description="Show the symbol type in headings (e.g. mod, class, meth, func and attr).",
),
] = False
Show the symbol type in headings (e.g. mod, class, meth, func and attr).
show_symbol_type_toc class-attribute instance-attribute Β€
show_symbol_type_toc: Annotated[
bool,
_Field(
group="headings",
description="Show the symbol type in the Table of Contents (e.g. mod, class, methd, func and attr).",
),
] = False
Show the symbol type in the Table of Contents (e.g. mod, class, methd, func and attr).
toc_label class-attribute instance-attribute Β€
toc_label: Annotated[
str,
_Field(
group="headings",
description="A custom string to override the autogenerated toc label of the root object.",
),
] = ""
A custom string to override the autogenerated toc label of the root object.
coerce classmethod Β€
coerce(**data: Any) -> MutableMapping[str, Any]
Create an instance from a dictionary.
CodeDoc dataclass Β€
CodeDoc(
macros: list[DocMacro],
functions: list[DocFunc],
global_vars: list[DocGlobalVar],
typedefs: dict[str, DocType],
)
A parsed C source file.
Attributes:
-
functions(list[DocFunc]) β"List of functions in the source file.
-
global_vars(list[DocGlobalVar]) βList of global variables in the source file.
-
macros(list[DocMacro]) βList of macros in the source file.
-
typedefs(dict[str, DocType]) βList of typedefs in the source file.
global_vars instance-attribute Β€
global_vars: list[DocGlobalVar]
List of global variables in the source file.
Comment dataclass Β€
A comment extracted from the source code.
Attributes:
-
last_line_number(int) βThe last line number of the comment in the source code.
-
text(str) βThe text of the comment.
DocFunc dataclass Β€
A parsed function.
Attributes:
DocGlobalVar dataclass Β€
DocMacro dataclass Β€
A parsed macro.
Attributes:
DocType dataclass Β€
A parsed typedef.
Attributes:
Docstring dataclass Β€
A parsed docstring.
Attributes:
FuncParam dataclass Β€
InOut Β€
Enumeration for parameter direction.
Attributes:
-
INβThe parameter is an input.
-
OUTβThe parameter is an output.
-
UNSPECIFIEDβThe direction is unspecified.
Macro dataclass Β€
A macro extracted from the source code.
Attributes:
-
line_number(int) βThe line number of the macro in the source code.
-
text(str) βThe text of the macro.
Param dataclass Β€
A parameter in a function signature.
Attributes:
SupportsQualsAndType Β€
Bases: Protocol
A protocol for types that can have qualifiers and a type.
Attributes:
-
quals(list[str]) βThe qualifiers of the type.
-
type(SupportsQualsAndType | TypeDecl | IdentifierType) βThe type of the node.
type instance-attribute Β€
type: SupportsQualsAndType | TypeDecl | IdentifierType
The type of the node.
TypeDecl Β€
TypeRef dataclass Β€
TypeRef(
name: TypeRef | str,
decl: TypeDecl,
quals: list[str],
params: list[TypeRef] | None = None,
)
A reference to a type in C.
Attributes:
-
decl(TypeDecl) βThe type declaration of the type reference.
-
name(TypeRef | str) βThe name of the type reference.
-
params(list[TypeRef] | None) βThe parameters of the type reference.
-
quals(list[str]) βThe qualifiers of the type reference.
params class-attribute instance-attribute Β€
The parameters of the type reference.
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(
handler_config: MutableMapping[str, Any],
tool_config: MkDocsConfig,
**kwargs: Any,
) -> CHandler
Simply return an instance of CHandler.
Parameters:
-
handler_config(MutableMapping[str, Any]) βThe handler configuration.
-
tool_config(MkDocsConfig) βThe tool (SSG) configuration.
Returns:
-
CHandlerβAn instance of
CHandler.