guidedoc_sphinx =============== .. rust:crate:: guidedoc_sphinx :synopsis: reStructuredText with the Sphinx layer: Sphinx's directives, roles, and domains, implemented independently on the base reader's extension interface (guidedoc_rst::Extension). 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 :rust:fn:`myst_settings `. .. code-block:: rust 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")); .. rubric:: Structs .. rust:struct:: pub struct AutodocMessage A problem the provider found, reported at the directive: a static message (with a hint, Elm style) and its arguments. .. rubric:: Fields .. rust:field:: pub message: Message The message. .. rust:field:: pub args: [Arg; 2] Its ``{0}`` and ``{1}`` arguments. .. rust:struct:: pub struct AutodocOption<'r> One option of an autodoc directive, as written; ``value`` is "" for a flag. .. rubric:: Fields .. rust:field:: pub name: &'r str The option's name ("members"). .. rust:field:: pub value: String Its value, joined and trimmed. .. rust:struct:: pub struct 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_context`` gives) and the document. .. rubric:: Fields .. rust:field:: pub domain: &'r str The domain whose provider runs ("py", "odin"). .. rust:field:: pub directive: &'r str The directive's name as its handler names it ("autoclass", "odin:autoproc"). .. rust:field:: pub argument: &'r str The argument, its lines joined by spaces. .. rust:field:: pub options: Vec> The options as written. .. rust:field:: pub content: &'r str The content, lines joined with "\\n". .. rust:field:: pub module: &'r str The current module (package). .. rust:field:: pub class: &'r str The current class (type). .. rust:field:: pub docname: &'r str The document's name. .. rust:struct:: pub struct AutodocResult What a provider generated: reStructuredText to parse where the directive stands, named as a source for diagnostics (""), and its messages. .. rubric:: Fields .. rust:field:: pub name: String The generated source's name. .. rust:field:: pub text: String The generated reStructuredText; empty adds nothing. .. rust:field:: pub messages: Vec What to report about it. .. rust:struct:: pub struct DirectiveInfo One directive a read knows, with the rules the reader checks before it runs. .. rubric:: Fields .. rust:field:: pub name: String The canonical name, such as ``note`` or ``py:function``. .. rust:field:: pub origin: Origin Where it is defined. .. rust:field:: pub requirement: Requirement What it needs. .. rust:field:: pub enabled: bool The configuration meets the requirement, so a read runs the directive. .. rust:field:: pub arg: ArgRule Whether it takes an argument. .. rust:field:: pub final_ws: bool The last argument may contain white space. .. rust:field:: pub content: ContentRule Whether it takes content. .. rust:field:: pub options: Vec The options it accepts. .. rust:struct:: pub struct RoleInfo One interpreted text role a read knows. .. rubric:: Fields .. rust:field:: pub name: String The name, such as ``emphasis``, ``ref`` or ``py:func``; ``external`` stands for every ``external:...`` role. .. rust:field:: pub origin: Origin Where it is defined. .. rust:field:: pub requirement: Requirement What it needs. .. rust:field:: pub enabled: bool The configuration meets the requirement. .. rust:struct:: pub struct 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 (:rust:const:`crate::INHERITANCE_DIAGRAM `). .. rubric:: Fields .. rust:field:: pub domain: String The domain the provider serves. .. rust:field:: pub provider: Arc The host's generator. .. rubric:: Trait Implementations .. rust:impl:: impl fmt::Debug for Autodoc :noindex: :for: Autodoc :trait: fmt::Debug .. rust:method:: fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result :noindex: .. rust:struct:: pub struct Config The conf.toml settings reading needs, with Sphinx's names. It reaches the reader through ``ReadOptions::extension`` (``guidedoc::read_extension(&config)``). Start from ``Config::default()``: several defaults are true. Settings the base reader owns (smart quotes, PEP and RFC base URLs, footnote reference space, language) live in ``settings``. .. rubric:: Fields .. rust:field:: pub settings: Settings The reStructuredText reader's settings. .. rust:field:: pub docname: String The document's name, e.g. "usage/intro". .. rust:field:: pub default_role: String The default role; empty means Docutils' title-reference. .. rust:field:: pub primary_domain: String The default domain ("py"); empty means none. .. rust:field:: pub highlight_language: String The default highlighting language ("default"). .. rust:field:: pub extlinks: Vec sphinx.ext.extlinks. .. rust:field:: pub rst_prolog: String Parsed before every reStructuredText document. .. rust:field:: pub rst_epilog: String Parsed after every reStructuredText document. .. rust:field:: pub numfig: bool Figures, tables, and code blocks are numbered. .. rust:field:: pub math_number_all: bool Every display equation is numbered. .. rust:field:: pub todo_include_todos: bool sphinx.ext.todo shows its todos. .. rust:field:: pub show_authors: bool sectionauthor and the other author directives show their authors. .. rust:field:: pub add_function_parentheses: bool "()" after the names of callables (true). .. rust:field:: pub add_module_names: bool Module names before object names (true). .. rust:field:: pub toc_object_entries: bool Objects have table of contents entries (true). .. rust:field:: pub toc_object_entries_show_parents: TocParents How much of an object's hierarchy its table of contents entry shows. .. rust:field:: pub manpages_url: String The manpage role's URL, with "{page}", "{section}", and "{path}" substituted. .. rust:field:: pub option_emphasise_placeholders: bool option_emphasise_placeholders. .. rust:field:: pub trim_doctest_flags: bool Doctest flags and ```` are hidden (true). .. rust:field:: pub version: String The default substitution \|version\|: the short version. .. rust:field:: pub release: String \|release\|: the full release. .. rust:field:: pub today: String \|today\|: today's date, already formatted. .. rust:field:: pub intersphinx: bool sphinx.ext.intersphinx: the :external: roles are read. .. rust:field:: pub intersphinx_resolve_self: String An external role naming this inventory is an ordinary reference. .. rust:field:: pub labels: Labels The info field labels ("Parameters", "Returns") in the document's language; empty ones are English. .. rust:field:: pub object_types: Vec The object types the project declares. .. rust:field:: pub directive_aliases: Vec Other names for directives. .. rust:field:: pub autodoc: Vec The autodoc providers, by domain; a domain without one leaves its auto directives unknown, as Sphinx without the extension. .. rubric:: Implementations .. rust:impl:: impl Config :noindex: :for: Config .. rust:method:: pub fn label(&self, l: Label) -> &str Returns label ``l`` in the document's language, English when it has none. .. rust:method:: pub fn autodoc_for(&self, domain: &str) -> Option<&Arc> Returns the autodoc provider of ``domain``. .. rubric:: Trait Implementations .. rust:impl:: impl Default for Config :noindex: :for: Config :trait: Default .. rust:method:: fn default() -> Config :noindex: Sphinx's defaults, with the base reader's default settings and smart quotes on. .. rust:struct:: pub struct DirectiveAlias Another name for a directive: ``name`` runs ``target``, which may name its domain ("py:function"). .. rubric:: Fields .. rust:field:: pub name: String The new name ("django-admin-option"). .. rust:field:: pub target: String The directive it names ("option"). .. rust:struct:: pub struct Extlink One sphinx.ext.extlinks entry: ``:name:``\ part\`\` links to ``url`` with ``%s`` replaced by the part; ``caption``, when set, is the link text with ``%s`` replaced likewise. .. rubric:: Fields .. rust:field:: pub name: String The role name. .. rust:field:: pub url: String The URL pattern. .. rust:field:: pub caption: String The caption pattern; empty shows the URL. .. rust:struct:: pub struct 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) or ``app.add_crossref_type`` (a directive that only makes a target). Both live in the standard domain. .. rubric:: Fields .. rust:field:: pub directive: String The directive name ("setting"). .. rust:field:: pub role: String The role name ("setting"); empty for none. .. rust:field:: pub index: String Sphinx's indextemplate, "pair: %s; setting"; empty for none. .. rust:field:: pub target: bool add_crossref_type: a target and an index entry, no description. .. rust:field:: pub first_word: bool The object's name is the signature up to its first space. .. rust:field:: pub display: String How the signature is shown, "%s" standing for it; empty shows it as written. .. rust:field:: pub program: bool The name becomes the program the options that follow belong to. .. rust:struct:: pub struct MystExtension The Sphinx layer as the "myst" reader's extension. Make the reader's settings with ``myst_settings``. .. rubric:: Trait Implementations .. rust:impl:: impl Extension for MystExtension :noindex: :for: MystExtension :trait: Extension .. rust:method:: fn begin(&self, h: &mut MdHost<'_, '_>) -> Result<(), Fail> :noindex: .. rust:method:: fn resolve(&self, h: &mut MdHost<'_, '_>) -> Result :noindex: .. rust:method:: fn shape(&self, h: &mut MdHost<'_, '_>, name: &str) -> Option :noindex: .. rust:method:: fn directive(&self, h: &mut MdHost<'_, '_>, d: &MdDirective<'_>) -> Result :noindex: .. rust:method:: fn role(&self, h: &mut MdHost<'_, '_>, r: &MdRole<'_>) -> Result :noindex: .. rust:method:: fn table(&self, h: &mut MdHost<'_, '_>, table: NodeId, span: SourceSpan, columns: usize) -> Result :noindex: Gives a table directive's title and options to the table the Markdown reader emits in its content. MyST tables are sized automatically. .. rubric:: Enums .. rust:enum:: pub enum Origin Where a directive or role is defined. .. rubric:: Variants .. rust:variant:: Docutils Docutils' standard reStructuredText. .. rust:variant:: Sphinx Sphinx's core layer (toctree, code-block, ...). .. rust:variant:: Domain(&'static str) A Sphinx domain, by name ("py", "std", ...). .. rust:variant:: Myst MyST Markdown only (``eval-rst``). .. rust:variant:: Project The project's configuration: an object type, a directive alias, an extlink. .. rust:enum:: pub enum Requirement What a directive or role needs besides the reader itself. .. rubric:: Variants .. rust:variant:: Nothing Nothing: it is always available. .. rust:variant:: Autodoc(&'static str) An autodoc provider for the named domain (or for :rust:const:`crate::INHERITANCE_DIAGRAM `), which the host supplies when the project enables the extension. .. rust:variant:: Intersphinx ``sphinx.ext.intersphinx`` (the ``external`` roles). .. rust:variant:: Declaration A declaration in the project's configuration, which the configuration has. .. rust:enum:: pub enum TocParents toc_object_entries_show_parents: how much of an object's hierarchy its table of contents entry shows. .. rubric:: Variants .. rust:variant:: Domain As the domain names it: Python's ``Class.method``, C++'s enclosing objects. .. rust:variant:: Hide The object's own name. .. rust:variant:: All Every part: ``module.Class.method``, ``ns::Class::f``. .. rubric:: Traits .. rust:trait:: pub trait 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``. .. rust:method:: fn generate(&self, request: &AutodocRequest<'_>) -> AutodocResult Generates the text ``request`` stands for. .. rubric:: Functions .. rust:function:: pub fn directives(config: &Config) -> Vec Lists every directive a read with ``config`` knows: 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 with ``enabled: false``. .. rust:function:: pub fn find_directive(config: &Config, name: &str) -> Option Finds the directive ``name`` as a read with ``config`` finds it outside any ``default-domain``: Sphinx's core, a full domain name, the primary domain, the standard domain, the project's declarations, then Docutils. ``None`` for a name no read knows (``eval-rst`` is found only in Markdown, and so not here). .. rust:function:: pub fn roles(config: &Config) -> Vec Lists every role a read with ``config`` knows: Docutils' standard roles, Sphinx's generic roles, each domain's roles under their full names, ``autolink``, the ``external`` roles, and the project's object type roles and extlinks. .. rust:function:: pub fn extension_supported(ext: &str) -> bool Tells whether conf.toml's extensions may name ``ext``: a built-in extension this reader implements natively. .. rust:function:: pub fn myst_settings(config: Config, myst: MystSettings) -> MystSettings Returns the "myst" reader's settings (``myst``) with the Sphinx layer's directives and roles configured by ``config``. Sphinx applies rst_prolog and rst_epilog to reStructuredText only, so they are left out; tabs are four columns, as in myst-parser. A ``myst.docname`` left empty takes ``config.docname``. .. rust:function:: pub fn reader() -> Reader Returns the "sphinx" reader descriptor, for a ``guidedoc::Registry``. .. rust:function:: pub fn read(ctx: &mut ReadContext<'_>) -> Result<(), Fail> Reads reStructuredText with the Sphinx layer. ``ctx.options.extension`` is a ``Config`` (``guidedoc::read_extension(&config)``), or empty for ``Config::default()``; another type is refused with ``InvalidInput``. The read keeps nothing of the configuration afterwards. Otherwise it fails as ``guidedoc_rst::read``. .. rust:function:: pub fn read_inline(ctx: &mut ReadContext<'_>, span: SourceSpan) -> Result<(), Fail> Parses a span of ``ctx.source`` as 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 are ``read``'s. .. rubric:: Constants .. rust:const:: pub const INHERITANCE_DIAGRAM: &str = "inheritance-diagram" The name the provider of sphinx.ext.inheritance_diagram's ``inheritance-diagram`` directive is registered under in ``Config::autodoc``. It is given the directive as an autodoc directive of the ``py`` domain and answers with a graph. .. rust:const:: pub const EXTENSIONS: [&str; 7] The extensions conf.toml may name: those this reader implements natively. .. rust:const:: pub const VERSION: &str = guidedoc::VERSION The layer's version: the project version. .. rust:const:: pub const CONFORMANCE: Conformance = Conformance::Partial How completely the layer implements Sphinx. .. rust:const:: pub const READER: Reader The "sphinx" reader: reStructuredText with the Sphinx layer. A value with no state: registering it twice or copying it is harmless.