Guidedog 手册 1.0.0-beta.16
语言
本页内容
Guidedog / 文档 1.0.0-beta.16

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 message: Message

The message.

pub args: [Arg; 2]

Its {0} and {1} arguments.

pub struct guidedoc_sphinx::AutodocOption<'r>

One option of an autodoc directive, as written; value is “” for a flag.

Fields

pub name: &'r str

The option’s name (“members”).

pub value: String

Its value, joined and trimmed.

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_context gives) 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 name: String

The generated source’s name.

pub text: String

The generated reStructuredText; empty adds nothing.

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 name: String

The canonical name, such as note or py:function.

pub origin: Origin

Where it is defined.

pub requirement: Requirement

What it needs.

pub enabled: bool

The configuration meets the requirement, so a read runs the directive.

pub arg: ArgRule

Whether it takes an argument.

pub final_ws: bool

The last argument may contain white space.

pub content: ContentRule

Whether it takes content.

pub options: Vec<OptSpec>

The options it accepts.

pub struct guidedoc_sphinx::RoleInfo

One interpreted text role a read knows.

Fields

pub name: String

The name, such as emphasis, ref or py:func; external stands for every external:... role.

pub origin: Origin

Where it is defined.

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 domain: String

The domain the provider serves.

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 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.

Fields

pub settings: Settings

The reStructuredText reader’s settings.

pub docname: String

The document’s name, e.g. “usage/intro”.

pub default_role: String

The default role; empty means Docutils’ title-reference.

pub primary_domain: String

The default domain (“py”); empty means none.

pub highlight_language: String

The default highlighting language (“default”).

sphinx.ext.extlinks.

pub rst_prolog: String

Parsed before every reStructuredText document.

pub rst_epilog: String

Parsed after every reStructuredText document.

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.

pub show_authors: bool

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 version: String

The default substitution |version|: the short version.

pub release: String

|release|: the full release.

pub today: String

|today|: today’s date, already formatted.

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 l in 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

impl Default for Config
fn default() -> Config

Sphinx’s defaults, with the base reader’s default settings and smart quotes on.

pub struct guidedoc_sphinx::DirectiveAlias

Another name for a directive: name runs target, which may name its domain (“py:function”).

Fields

pub name: String

The new name (“django-admin-option”).

pub target: String

The directive it names (“option”).

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.

Fields

pub name: String

The role name.

pub url: String

The URL pattern.

pub caption: String

The caption pattern; empty shows the URL.

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) or app.add_crossref_type (a directive that only makes a target). Both live in the standard domain.

Fields

pub directive: String

The directive name (“setting”).

pub role: String

The role name (“setting”); empty for none.

pub index: String

Sphinx’s indextemplate, “pair: %s; setting”; empty for none.

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 display: String

How the signature is shown, “%s” standing for it; empty shows it as written.

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 (the external roles).

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 request stands for.

Functions

pub fn guidedoc_sphinx::directives(config: &Config) -> Vec<DirectiveInfo>

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.

pub fn guidedoc_sphinx::find_directive(config: &Config, name: &str) -> Option<DirectiveInfo>

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).

pub fn guidedoc_sphinx::roles(config: &Config) -> Vec<RoleInfo>

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.

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 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.

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.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.

pub fn guidedoc_sphinx::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.

Constants

pub const guidedoc_sphinx::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.

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.

pub const guidedoc_sphinx::READER: Reader

The “sphinx” reader: reStructuredText with the Sphinx layer. A value with no state: registering it twice or copying it is harmless.