guidedoc_sphinx¶
reStructuredText with the Sphinx layer: Sphinx’s directives, roles, and domains, implemented independently on the base reader’s extension interface (guidedoc_rst::Extension). It produces the shapes of docs/manual/internals/ast.rst, «Sphinx layer»; cross-document work (toctrees, cross-references, numbering) is left to the project host. The same handlers serve MyST Markdown read by the «myst» reader: see myst_settings.
use guidedoc::{Workspace, default_request, dump_to_string, read_document, read_extension};
use guidedoc_sphinx::{Config, reader};
let config = Config { primary_domain: "py".into(), ..Config::default() };
let mut request = default_request("api.rst", ".. py:function:: f(x)\n", "sphinx", "html");
request.read.extension = Some(read_extension(&config));
let mut ws = Workspace::new();
let doc = read_document(&mut ws, &reader(), &request).unwrap();
assert!(dump_to_string(doc).contains("desc-signature"));
Structs
- pub struct guidedoc_sphinx::AutodocMessage¶
-
A problem the provider found, reported at the directive: a static message (with a hint, Elm style) and its arguments.
Fields
- pub struct guidedoc_sphinx::AutodocOption<'r>¶
-
One option of an autodoc directive, as written;
valueis «» for a flag.Fields
- pub name: &'r str¶
-
The option’s name («members»).
- pub struct guidedoc_sphinx::AutodocRequest<'r>¶
-
One autodoc directive and the context it needs: the current module and class (for Python, py:module and py:class; for other domains what their
autodoc_contextgives) and the document.Fields
- pub domain: &'r str¶
-
The domain whose provider runs («py», «odin»).
- pub directive: &'r str¶
-
The directive’s name as its handler names it («autoclass», «odin:autoproc»).
- pub argument: &'r str¶
-
The argument, its lines joined by spaces.
- pub options: Vec<AutodocOption<'r>>¶
-
The options as written.
- pub content: &'r str¶
-
The content, lines joined with «\n».
- pub module: &'r str¶
-
The current module (package).
- pub class: &'r str¶
-
The current class (type).
- pub docname: &'r str¶
-
The document’s name.
- pub struct guidedoc_sphinx::AutodocResult¶
-
What a provider generated: reStructuredText to parse where the directive stands, named as a source for diagnostics («<autodoc flask.Flask>»), and its messages.
Fields
- pub messages: Vec<AutodocMessage>¶
-
What to report about it.
- pub struct guidedoc_sphinx::DirectiveInfo¶
-
One directive a read knows, with the rules the reader checks before it runs.
Fields
- pub requirement: Requirement¶
-
What it needs.
- pub enabled: bool¶
-
The configuration meets the requirement, so a read runs the directive.
- pub final_ws: bool¶
-
The last argument may contain white space.
- pub content: ContentRule¶
-
Whether it takes content.
- pub struct guidedoc_sphinx::RoleInfo¶
-
One interpreted text role a read knows.
Fields
- pub name: String¶
-
The name, such as
emphasis,reforpy:func;externalstands for everyexternal:...role.
- pub requirement: Requirement¶
-
What it needs.
- pub enabled: bool¶
-
The configuration meets the requirement.
- pub struct guidedoc_sphinx::Autodoc¶
-
The autodoc provider of one domain: what generates the text its auto directives stand for («py» for automodule and the others, «odin» for odin:autopackage, …), or of a directive generated from source (
crate::INHERITANCE_DIAGRAM).Fields
- pub provider: Arc<dyn AutodocProvider>¶
-
The host’s generator.
Trait Implementations
- impl fmt::Debug for Autodoc
-
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
- pub struct guidedoc_sphinx::Config¶
-
The conf.toml settings reading needs, with Sphinx’s names. It reaches the reader through
ReadOptions::extension(guidedoc::read_extension(&config)). Start fromConfig::default(): several defaults are true. Settings the base reader owns (smart quotes, PEP and RFC base URLs, footnote reference space, language) live insettings.Fields
- pub numfig: bool¶
-
Figures, tables, and code blocks are numbered.
- pub math_number_all: bool¶
-
Every display equation is numbered.
- pub todo_include_todos: bool¶
-
sphinx.ext.todo shows its todos.
-
sectionauthor and the other author directives show their authors.
- pub add_function_parentheses: bool¶
-
«()» after the names of callables (true).
- pub add_module_names: bool¶
-
Module names before object names (true).
- pub toc_object_entries: bool¶
-
Objects have table of contents entries (true).
- pub toc_object_entries_show_parents: TocParents¶
-
How much of an object’s hierarchy its table of contents entry shows.
- pub manpages_url: String¶
-
The manpage role’s URL, with «{page}», «{section}», and «{path}» substituted.
- pub option_emphasise_placeholders: bool¶
-
option_emphasise_placeholders.
- pub trim_doctest_flags: bool¶
-
Doctest flags and
<BLANKLINE>are hidden (true).
- pub intersphinx: bool¶
-
sphinx.ext.intersphinx: the :external: roles are read.
- pub intersphinx_resolve_self: String¶
-
An external role naming this inventory is an ordinary reference.
- pub labels: Labels¶
-
The info field labels («Parameters», «Returns») in the document’s language; empty ones are English.
- pub object_types: Vec<ObjectType>¶
-
The object types the project declares.
- pub directive_aliases: Vec<DirectiveAlias>¶
-
Other names for directives.
- pub autodoc: Vec<Autodoc>¶
-
The autodoc providers, by domain; a domain without one leaves its auto directives unknown, as Sphinx without the extension.
Implementations
- impl Config
-
- pub fn label(&self, l: Label) -> &str¶
-
Returns label
lin the document’s language, English when it has none.
- pub fn autodoc_for(&self, domain: &str) -> Option<&Arc<dyn AutodocProvider>>¶
-
Returns the autodoc provider of
domain.
Trait Implementations
- pub struct guidedoc_sphinx::DirectiveAlias¶
-
Another name for a directive:
namerunstarget, which may name its domain («py:function»).Fields
- pub struct guidedoc_sphinx::Extlink¶
-
One sphinx.ext.extlinks entry:
:name:part`` links tourlwith%sreplaced by the part;caption, when set, is the link text with%sreplaced likewise.Fields
- pub struct guidedoc_sphinx::ObjectType¶
-
An object type a project declares, as a Sphinx extension declares one with
app.add_object_type(a directive that describes an object and a role that refers to it) orapp.add_crossref_type(a directive that only makes a target). Both live in the standard domain.Fields
- pub target: bool¶
-
add_crossref_type: a target and an index entry, no description.
- pub first_word: bool¶
-
The object’s name is the signature up to its first space.
- pub program: bool¶
-
The name becomes the program the options that follow belong to.
- pub struct guidedoc_sphinx::MystExtension¶
-
The Sphinx layer as the «myst» reader’s extension. Make the reader’s settings with
myst_settings.Trait Implementations
- impl Extension for MystExtension
-
- fn begin(&self, h: &mut MdHost<'_, '_>) -> Result<(), Fail>
- fn resolve(&self, h: &mut MdHost<'_, '_>) -> Result<bool, Fail>
- fn shape(&self, h: &mut MdHost<'_, '_>, name: &str) -> Option<DirectiveShape>
- fn directive(&self, h: &mut MdHost<'_, '_>, d: &MdDirective<'_>) -> Result<DirectiveResult, Fail>
- fn role(&self, h: &mut MdHost<'_, '_>, r: &MdRole<'_>) -> Result<bool, Fail>
- fn table(&self, h: &mut MdHost<'_, '_>, table: NodeId, span: SourceSpan, columns: usize) -> Result<bool, Fail>
-
Gives a table directive’s title and options to the table the Markdown reader emits in its content. MyST tables are sized automatically.
Enums
- pub enum guidedoc_sphinx::Origin¶
-
Where a directive or role is defined.
Variants
- Docutils¶
-
Docutils” standard reStructuredText.
- Sphinx¶
-
Sphinx’s core layer (toctree, code-block, …).
- Domain(&'static str)¶
-
A Sphinx domain, by name («py», «std», …).
- Myst¶
-
MyST Markdown only (
eval-rst).
- Project¶
-
The project’s configuration: an object type, a directive alias, an extlink.
- pub enum guidedoc_sphinx::Requirement¶
-
What a directive or role needs besides the reader itself.
Variants
- Nothing¶
-
Nothing: it is always available.
- Autodoc(&'static str)¶
-
An autodoc provider for the named domain (or for
crate::INHERITANCE_DIAGRAM), which the host supplies when the project enables the extension.
- Intersphinx¶
-
sphinx.ext.intersphinx(theexternalroles).
- Declaration¶
-
A declaration in the project’s configuration, which the configuration has.
- pub enum guidedoc_sphinx::TocParents¶
-
toc_object_entries_show_parents: how much of an object’s hierarchy its table of contents entry shows.
Variants
- Domain¶
-
As the domain names it: Python’s
Class.method, C++”s enclosing objects.
- Hide¶
-
The object’s own name.
- All¶
-
Every part:
module.Class.method,ns::Class::f.
Traits
- pub trait guidedoc_sphinx::AutodocProvider: Send + Sync¶
-
The host’s generator of a domain’s auto directives. It belongs to the caller’s trust boundary; it is shared between reads, so it takes
&self.- fn generate(&self, request: &AutodocRequest<'_>) -> AutodocResult¶
-
Generates the text
requeststands for.
Functions
- pub fn guidedoc_sphinx::directives(config: &Config) -> Vec<DirectiveInfo>¶
-
Lists every directive a read with
configknows: Sphinx’s core directives (which replace Docutils” directives of the same name), each domain’s directives under their full names, the Docutils directives Sphinx does not replace,eval-rst, then the project’s object types and directive aliases. Directives that need a missing autodoc provider are listed withenabled: false.
- pub fn guidedoc_sphinx::find_directive(config: &Config, name: &str) -> Option<DirectiveInfo>¶
-
Finds the directive
nameas a read withconfigfinds it outside anydefault-domain: Sphinx’s core, a full domain name, the primary domain, the standard domain, the project’s declarations, then Docutils.Nonefor a name no read knows (eval-rstis found only in Markdown, and so not here).
- pub fn guidedoc_sphinx::roles(config: &Config) -> Vec<RoleInfo>¶
-
Lists every role a read with
configknows: Docutils” standard roles, Sphinx’s generic roles, each domain’s roles under their full names,autolink, theexternalroles, and the project’s object type roles and extlinks.
- pub fn guidedoc_sphinx::extension_supported(ext: &str) -> bool¶
-
Tells whether conf.toml’s extensions may name
ext: a built-in extension this reader implements natively.
- pub fn guidedoc_sphinx::myst_settings(config: Config, myst: MystSettings) -> MystSettings¶
-
Returns the «myst» reader’s settings (
myst) with the Sphinx layer’s directives and roles configured byconfig. Sphinx applies rst_prolog and rst_epilog to reStructuredText only, so they are left out; tabs are four columns, as in myst-parser. Amyst.docnameleft empty takesconfig.docname.
- pub fn guidedoc_sphinx::reader() -> Reader¶
-
Returns the «sphinx» reader descriptor, for a
guidedoc::Registry.
- pub fn guidedoc_sphinx::read(ctx: &mut ReadContext<'_>) -> Result<(), Fail>¶
-
Reads reStructuredText with the Sphinx layer.
ctx.options.extensionis aConfig(guidedoc::read_extension(&config)), or empty forConfig::default(); another type is refused withInvalidInput. The read keeps nothing of the configuration afterwards. Otherwise it fails asguidedoc_rst::read.
- pub fn guidedoc_sphinx::read_inline(ctx: &mut ReadContext<'_>, span: SourceSpan) -> Result<(), Fail>¶
-
Parses a span of
ctx.sourceas reStructuredText inline content with Sphinx’s roles, for a translated message (guidedoc::ReadInlineFn). rst_prolog and rst_epilog do not apply to a message. Settings and failures areread’s.
Constants
- pub const guidedoc_sphinx::INHERITANCE_DIAGRAM: &str = "inheritance-diagram"¶
-
The name the provider of sphinx.ext.inheritance_diagram’s
inheritance-diagramdirective is registered under inConfig::autodoc. It is given the directive as an autodoc directive of thepydomain and answers with a graph.
- pub const guidedoc_sphinx::EXTENSIONS: [&str; 7]¶
-
The extensions conf.toml may name: those this reader implements natively.
- pub const guidedoc_sphinx::VERSION: &str = guidedoc::VERSION¶
-
The layer’s version: the project version.
- pub const guidedoc_sphinx::CONFORMANCE: Conformance = Conformance::Partial¶
-
How completely the layer implements Sphinx.