guidedoc_rst ============ .. rust:crate:: guidedoc_rst :synopsis: The reStructuredText reader of Guidedoc: lines, block structure, explicit markup, and the standard Docutils directives, implemented independently from the Docutils markup specification. The reStructuredText reader of Guidedoc: lines, block structure, explicit markup, and the standard Docutils directives, implemented independently from the Docutils markup specification. Inline markup and reference resolution live in ``guidedoc_rst_inline``, which this crate drives. .. code-block:: rust use guidedoc::{Registry, Workspace, default_request, dump_to_string, read_document}; let mut ws = Workspace::new(); let mut request = default_request("x.rst", "Hello *world*.\n", "rst", "html"); request.read.promote_title = false; let doc = read_document(&mut ws, &guidedoc_rst::reader(), &request).unwrap(); assert!(dump_to_string(doc).starts_with("document\n paragraph\n")); Dialects (the Sphinx layer) add directives and roles through :rust:trait:`Extension ` and read with :rust:fn:`read_with `; another markup (MyST) runs the directives through :rust:trait:`Host `, :rust:fn:`embed_begin `, and :rust:fn:`Parser::run_hosted `. .. rubric:: Re-exports .. rust:use:: pub use settings::SmartQuotes .. rust:use:: pub use guidedoc_rst_inline::Role .. rust:use:: pub use guidedoc_rst_inline::RoleBase .. rust:use:: pub use guidedoc_rst_inline::RoleCall .. rust:use:: pub use guidedoc_rst_inline::standard_role .. rust:use:: pub use guidedoc_rst_inline::standard_roles .. rubric:: Modules - :rust:mod:`guidedoc_rst::messages` -- The reader's messages. .. rubric:: Structs .. rust:struct:: pub struct DirOption<'d> One option a directive was given: its specification, its value lines (the rest of the marker line, then the continuation lines), and where it was written. .. rubric:: Fields .. rust:field:: pub spec: OptSpec The option's specification. .. rust:field:: pub lines: Vec> The value lines, trimmed. .. rust:field:: pub span: SourceSpan The option's lines in the source. .. rust:struct:: pub struct Directive<'d> A directive split into its parts and checked against its rules. Handlers read it; the lines are views of the current source (``Parser::src``). .. rubric:: Fields .. rust:field:: pub name: &'d str The directive name as written. .. rust:field:: pub span: SourceSpan The whole directive block. .. rust:field:: pub name_span: SourceSpan The name on the marker line. .. rust:field:: pub arg: Vec> The argument lines, trimmed; empty when there is no argument. .. rust:field:: pub arg_block: Vec> The argument lines with their relative indentation. .. rust:field:: pub options: Vec> The options given, in order. .. rust:field:: pub content: Vec> The content lines, without leading and trailing blank lines. .. rust:field:: pub sections: bool The directive stands where sections are allowed. .. rust:field:: pub subst: bool The directive is inside a substitution definition. .. rust:field:: pub subst_name: String The name of the substitution definition it is in, as written. .. rubric:: Implementations .. rust:impl:: impl<'d> Directive<'d> :noindex: :for: Directive<'d> .. rust:method:: pub fn handler(&self) -> Option<&DirectiveHandler<'d>> Returns the dialect's handler that runs the directive; ``None`` for a standard one. .. rust:method:: pub fn option(&self, name: &str) -> Option<&DirOption<'d>> Returns the option called ``name`` the directive was given. .. rust:method:: pub fn has_option(&self, name: &str) -> bool Tells whether the directive was given option ``name``, flags included. .. rust:method:: pub fn option_lines(&self, name: &str) -> Option<&[Line<'d>]> Returns the value lines of option ``name``. .. rust:method:: pub fn option_value(&self, name: &str) -> Option> Returns option ``name``'s value lines joined by spaces and trimmed; ``None`` when the option was not given. .. rust:method:: pub fn option_text(&self, name: &str) -> Option> Returns option ``name``'s value lines joined by line breaks and trimmed, as text options such as ``:start-after:`` match text that spans lines. .. rust:method:: pub fn argument(&self) -> Cow<'d, str> The argument lines joined by spaces. .. rust:struct:: pub struct DirectiveHandler<'h> A dialect's directive: its rules, checked by the reader before it runs, and a tag the dialect chooses to find its own code again in ``Extension::run_directive``. .. rubric:: Fields .. rust:field:: pub name: &'h str The directive's canonical name ("py:function"), compared case-insensitively. .. 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: &'h [OptSpec] The options it accepts. .. rust:field:: pub tag: usize The dialect's own identification of the handler, such as a table index. .. rust:struct:: pub struct DirectiveShape<'h> How a directive takes its parts, for a host that checks them itself. .. rubric:: Fields .. 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: &'h [OptSpec] Its options. .. rust:struct:: pub struct HostDirective<'s> A directive the host has split into its parts. .. rubric:: Fields .. rust:field:: pub name: &'s str The directive name. .. rust:field:: pub name_span: SourceSpan Where the name was written. .. rust:field:: pub span: SourceSpan The whole directive. .. rust:field:: pub arg: Vec> The argument lines; empty when there is none. .. rust:field:: pub options: Vec> The options, in order. .. rust:field:: pub content: Vec> The content lines. .. rust:field:: pub sections: bool The directive stands where sections are allowed. .. rust:struct:: pub struct HostItem<'s> One item of a host's bullet list: its content lines and the index in the given lines of the line it starts on. .. rubric:: Fields .. rust:field:: pub lines: Vec> The item's content. .. rust:field:: pub start: usize Where the item starts in the lines ``Host::items`` was given. .. rust:struct:: pub struct HostOption<'s> A directive option as the host wrote it: its name and value lines. .. rubric:: Fields .. rust:field:: pub name: &'s str The option name. .. rust:field:: pub value: Vec> The value lines. .. rust:field:: pub span: SourceSpan Where it was written. .. rust:struct:: pub struct Line<'s> One input line in columns: tabs expanded, trailing white space stripped. Lines are ``Copy`` views; cutting one never copies text. .. rubric:: Fields .. rust:field:: pub text: &'s str The line's text from its current column. .. rubric:: Implementations .. rust:impl:: impl<'s> Line<'s> :noindex: :for: Line<'s> .. rust:method:: pub fn from_view(view: LineView<'s>) -> Line<'s> Makes a line of source text that needs no expansion (a host's view of a line whose tabs it handles itself, or text without tabs). .. rust:method:: pub fn is_blank(&self) -> bool Tells whether the line has no text (white space is stripped when lines are made). .. rust:method:: pub fn is_indented(&self) -> bool Tells whether the line starts with a space. .. rust:method:: pub fn cut(self, k: usize) -> Line<'s> Drops the first ``k`` columns (bytes of the expanded text). .. rust:method:: pub fn head(self, n: usize) -> Line<'s> Keeps the first ``n`` columns, without trailing spaces. .. rust:method:: pub fn start(&self, tab: usize) -> u32 Returns the source offset where the line's text starts, with tab stops ``tab``. .. rust:method:: pub fn end(&self, tab: usize) -> u32 Returns the source offset where the line's text ends, with tab stops ``tab``. .. rust:method:: pub fn view(&self, tab: usize) -> LineView<'s> Returns a view of the source bytes the line covers, tabs unexpanded, for inline parsing, whose spans then stay exact. .. rust:struct:: pub struct Parser<'p, 'a> The block parser: a read context, the reader's state, and the dialect's handlers and host. Handlers receive it; ``ctx.b`` builds nodes. .. rubric:: Fields .. rust:field:: pub ctx: &'p mut ReadContext<'a> The read context: builder, options, sources, reports. .. rubric:: Implementations .. rust:impl:: impl<'p, 'a> Parser<'p, 'a> :noindex: :for: Parser<'p, 'a> .. rust:method:: pub fn add_common(&mut self, id: NodeId, d: &Directive<'_>, class_opt: &str) -> Result<(), Fail> Adds the ``:class:`` (or ``class_opt``) and ``:name:`` options as attributes. Directive nodes keep their Name attribute for the directive name, so ``:name:`` becomes Custom "name" there. .. rust:method:: pub fn directive_node(&mut self, d: &Directive<'_>, name: &str) -> Result Opens a generic Directive node named ``name``. .. rust:method:: pub fn custom(&mut self, id: NodeId, name: &str, value: &str) -> Result<(), Fail> Adds a Custom attribute ``name`` = ``value`` to node ``id``; both are copied. .. rust:impl:: impl<'p, 'a> Parser<'p, 'a> :noindex: :for: Parser<'p, 'a> .. rust:method:: pub fn directive_shape(&self, name: &str) -> Option> Looks directive ``name`` up as the reader would, the dialect's handlers first. .. rust:method:: pub fn run_hosted(&mut self, h: &HostDirective<'_>) -> Result Checks and runs a directive written in the host markup. Options are checked as in reStructuredText; a host with other rules checks them first (``directive_shape``, ``option_problem``) and passes only those it keeps. Fails only when the builder fails. .. rust:method:: pub fn host_lines<'s>(&self, views: &[LineView<'s>], buf: &'s mut String) -> Vec> Makes lines of a host's views of source text: tabs are expanded to the parser's tab stops into ``buf``, as the reader's own lines are. .. rust:method:: pub fn host_views<'s>(&self, lines: &[Line<'s>]) -> Vec> Gives the host the source text of lines, tabs unexpanded. .. rust:method:: pub fn lend(&mut self, f: impl FnOnce(&mut ReadContext<'a>, &mut ReaderState) -> R) -> R Lends the read context and the reader's state to ``f``. A host that parses nested content with a reader of its own, whose directives run through this reader again, uses it to move the state where those handlers find it (and back) while the context is with its reader. .. rust:method:: pub fn embed_end(&mut self) -> Result<(), Fail> Ends an embedded read: runs the dialect's end hook, closes sections, reports what was left dangling, and resolves the document as ``read`` does. The state's storage then goes back to the workspace (``ReaderState::end``). .. rust:impl:: impl Parser<'_, '_> :noindex: :for: Parser<'_, '_> .. rust:method:: pub fn pool_classes(&mut self, s: &str) -> Result, Fail> Writes white-space separated class names as identifiers, one space apart, to the text pool; ``None`` when a name has no letters or there is none. .. rust:method:: pub fn pool_lower(&mut self, s: &str) -> Result Writes ``s`` in lower case (ASCII) to the text pool. .. rust:method:: pub fn push_lines(&mut self, lines: &[Line<'_>], sep: &str) -> Result<(), Fail> Pushes ``lines`` joined by ``sep`` onto the text run being built (between ``Builder::text_open`` and ``text_close``). .. rust:method:: pub fn pool_lines(&mut self, lines: &[Line<'_>], sep: &str) -> Result Writes ``lines`` joined by ``sep`` to the text pool. .. rust:method:: pub fn code_text(&mut self, lines: &[Line<'_>]) -> Result Writes ``lines`` to the text pool, each ending in "\\n" (code). .. rust:impl:: impl<'p, 'a> Parser<'p, 'a> :noindex: :for: Parser<'p, 'a> .. rust:method:: pub fn b(&mut self) -> &mut Builder<'a> The builder of the document being read. .. rust:method:: pub fn src(&self) -> SourceId The source the current lines come from. .. rust:method:: pub fn tab(&self) -> usize The tab stops of the current source. .. rust:method:: pub fn is_hosted(&self) -> bool Tells whether the running directive was written in the host markup. .. rust:method:: pub fn inline_state(&mut self) -> &mut InlineState The inline state: custom roles and the default role. .. rust:method:: pub fn stack_guard(&self) -> StackGuard The stack guard of the read, for a handler's own recursion (a C++ parser). .. rust:method:: pub fn apply_host_role(&mut self, name: &str, lines: &[LineView<'_>], content: std::ops::Range) -> Result<(), Fail> Runs role ``name`` on interpreted text written in the host markup (MyST's ``{name}`` roles), with the dialect's roles first; see ``guidedoc_rst_inline::apply_host_role``. Fails only when the builder fails. .. rust:method:: pub fn take_pending_classes(&mut self) -> Option Takes the classes a class directive left for the next element, if any. .. rust:method:: pub fn report(&mut self, m: guidedoc::Message, span: SourceSpan, a: Arg, b: Arg) Reports message ``m`` at ``span`` with its arguments. Reports never fail the read. .. rust:method:: pub fn open(&mut self, kind: NodeKind, span: SourceSpan) -> Result Begins an element and gives it the classes of a preceding class directive. .. rust:method:: pub fn close(&mut self, id: NodeId) -> Result<(), Fail> Ends the element ``open`` returned ``id`` for. .. rust:method:: pub fn span_of(&self, first: &Line<'_>, last: &Line<'_>) -> SourceSpan The source span from the start of ``first`` to the end of ``last``, in the current source, clamped to its text. .. rust:method:: pub fn line_span(&self, l: &Line<'_>) -> SourceSpan The source span of one line. .. rust:method:: pub fn lines_span(&self, lines: &[Line<'_>]) -> SourceSpan The source span of ``lines`` without trailing blank lines; empty lines give an empty span at the start of the source. .. rust:method:: pub fn inline(&mut self, lines: &[Line<'_>]) -> Result<(), Fail> Parses ``lines`` as inline content of the open node, in the markup of the running directive (see ``Host``). .. rust:method:: pub fn inline_views(&mut self, views: &[LineView<'_>]) -> Result<(), Fail> Parses source views as reStructuredText inline content of the open node. .. rust:method:: pub fn inline_node(&mut self, kind: NodeKind, lines: &[Line<'_>]) -> Result<(), Fail> Adds a node of ``kind`` holding ``lines`` parsed as inline content; nothing for no lines. .. rust:method:: pub fn parse_body(&mut self, lines: &[Line<'_>], sections: bool, each: Option) -> Result<(), Fail> Parses nested body content of the open node in the markup of the running directive (see ``Host``); outside hosted directives it is ``parse_blocks``. .. rust:method:: pub fn parse_blocks(&mut self, lines: &[Line<'_>], sections: bool, each: Option) -> Result<(), Fail> Parses body elements as reStructuredText. ``sections`` allows titles and transitions; ``each`` gives classes to every element parsed at this level (the class directive's content). .. rust:impl:: impl Parser<'_, '_> :noindex: :for: Parser<'_, '_> .. rust:method:: pub fn enter_source(&mut self, id: SourceId, tab: usize) -> SourceFrame Makes the lines of source ``id`` current, with tab stops ``tab``, for spans and inline parsing; ``leave_source`` restores the previous source. .. rust:method:: pub fn leave_source(&mut self, frame: SourceFrame) Makes the source ``enter_source`` returned ``frame`` for current again. .. rust:method:: pub fn parse_source(&mut self, id: SourceId, sections: bool) -> Result<(), Fail> Parses a whole registered source (``ReadContext::add_source``) as body content at the current position, as if its lines stood there. ``sections`` allows titles. .. rust:impl:: impl Parser<'_, '_> :noindex: :for: Parser<'_, '_> .. rust:method:: pub fn find_role(&mut self, name: &str) -> Result, Fail> Returns the index of the role the document defined under ``name`` with the role directive, if any. The search spends work budget. .. rust:method:: pub fn class_directive(&mut self, d: &Directive<'_>) -> Result<(), Fail> Runs the class directive: its classes go to the content's elements or, without content, to the next element; invalid names are reported. .. rust:impl:: impl Parser<'_, '_> :noindex: :for: Parser<'_, '_> .. rust:method:: pub fn place_titled(&mut self, lines: &[Line<'_>]) -> Result<(), Fail> Prepares for titled content (``parse_titled``) as Sphinx's only directive does: when the content's first title has an adornment the document already uses, the content stands where a title of that level would, so deeper sections close first. .. rust:method:: pub fn parse_titled(&mut self, lines: &[Line<'_>]) -> Result<(), Fail> Parses content in which titles begin sections, in a title context of its own (Sphinx's nested parse with titles): adornments take levels afresh, the first nesting in the innermost open section, and the sections close when the content ends. The surrounding adornments are kept for what follows. .. rust:impl:: impl Parser<'_, '_> :noindex: :for: Parser<'_, '_> .. rust:method:: pub fn take_table_extra(&mut self) -> Option Takes the title and options of the hosted table directive whose content is being parsed, for the first table the host emits; ``None`` outside one or once taken. .. rust:method:: pub fn table_decorate(&mut self, id: NodeId, span: SourceSpan, cols: usize, widths: &[usize], extra: Option<&mut TableExtra>) -> Result<(), Fail> Gives an open Table, before its rows, its widths and a table directive's attributes and title. A host calls it for the table it emits inside a table directive (``take_table_extra``). .. rubric:: Trait Implementations .. rust:impl:: impl fmt::Debug for Parser<'_, '_> :noindex: :for: Parser<'_, '_> :trait: fmt::Debug .. rust:method:: fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result :noindex: .. rust:struct:: pub struct ReaderState The reader's state of one document: the current source, tab stops, section levels, pending classes, the inline state, and nesting depth. ``read`` keeps one for the call; a host markup that embeds the reader (``embed_begin``) keeps it between calls and views it as a ``Parser`` with ``ReaderState::parser``. .. rubric:: Implementations .. rust:impl:: impl ReaderState :noindex: :for: ReaderState .. rust:method:: pub fn new(ctx: &mut ReadContext<'_>, settings: &Settings) -> ReaderState Prepares the state for the main source of ``ctx`` with ``settings``, with the storage an earlier read left in the workspace (``end`` gives it back). .. rust:method:: pub fn end(&mut self, ctx: &mut ReadContext<'_>) Gives the state's storage back to the workspace for the next read; call it once when the read ends (``Parser::embed_end`` and ``read_inline`` do). The state stays usable, with empty buffers. .. rust:method:: pub fn parser<'p, 'a>(&'p mut self, ctx: &'p mut ReadContext<'a>, ext: Option<&'p dyn Extension>, host: Option<&'p dyn Host>) -> Parser<'p, 'a> Views the state as a parser over ``ctx``, with a dialect's handlers and a host. .. rubric:: Trait Implementations .. rust:impl:: impl fmt::Debug for ReaderState :noindex: :for: ReaderState :trait: fmt::Debug .. rust:method:: fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result :noindex: .. rust:struct:: pub struct SourceFrame Where the parser stood before ``enter_source``. .. rust:struct:: pub struct Settings The reader's settings. They reach ``read`` through ``ReadOptions::extension``, made with ``guidedoc::read_extension(&settings)``; settings of another type are refused. Start from ``Settings::default()`` (Docutils' defaults): the bibliographic fields are on. Directive and role handlers (``Extension``) and a host markup (``Host``) are not settings: a dialect passes them to ``read_with`` and ``embed_begin``. .. rubric:: Fields .. rust:field:: pub pep_references: bool Implicit "PEP nnn" references in running text become links. .. rust:field:: pub rfc_references: bool Implicit "RFC nnn" references in running text become links. .. rust:field:: pub pep_base_url: String "" means ``https://peps.python.org/``. .. rust:field:: pub rfc_base_url: String "" means ``https://datatracker.ietf.org/doc/html/``. .. rust:field:: pub trim_footnote_reference_space: bool White space before a footnote reference is removed. .. rust:field:: pub smart_quotes: SmartQuotes Typographic quotation marks, apostrophes, dashes, and ellipses in text. .. rust:field:: pub smart_quotes_locales: String Quotation marks per language, overriding the built-in ones, as ``"tag:“”‘’,tag2:«»‹›"``: primary open and close, then secondary open and close. .. rust:field:: pub language: String BCP 47 tag of the document language: bibliographic field names, generated titles, and quotation marks. "" means "en". .. rust:field:: pub docinfo: bool A field list first in the document becomes bibliographic data (docinfo). .. rust:field:: pub sectsubtitle: bool A lone subsection title becomes the section's subtitle. .. rust:field:: pub tab_width: usize Tab stops; zero means ``ReadOptions::tab_width``, which zero makes 8. .. rust:field:: pub character_level_inline_markup: bool Inline markup is recognized inside words (Docutils' ``character_level_inline_markup``). .. rubric:: Trait Implementations .. rust:impl:: impl Default for Settings :noindex: :for: Settings :trait: Default .. rust:method:: fn default() -> Self :noindex: .. rust:struct:: pub struct OptSpec One option a directive accepts. .. rubric:: Fields .. rust:field:: pub name: &'static str The option name, compared exactly. .. rust:field:: pub kind: OptType Its value type. .. rust:field:: pub choices: &'static str Space-separated choices, for ``OptType::Choice``. .. rust:struct:: pub struct TableExtra What a table directive adds to its table: a title and attributes. A host markup that emits the table of a hosted table directive takes it with ``Parser::take_table_extra`` and passes it to ``Parser::table_decorate``. .. rubric:: Fields .. rust:field:: pub width_class: &'static str "colwidths-auto" or "colwidths-given" from ``:widths:``; a host may set it. .. rubric:: Enums .. rust:enum:: pub enum HostedResult The outcome of ``run_hosted``. .. rubric:: Variants .. rust:variant:: Ran The directive ran. .. rust:variant:: Unknown No directive has that name; nothing was reported. .. rust:variant:: Failed The arguments, options, or content were refused and reported. .. rust:enum:: pub enum ArgRule Whether a directive takes an argument. .. rubric:: Variants .. rust:variant:: None No argument; words on the directive line are content. .. rust:variant:: Optional An argument may be given. .. rust:variant:: Required An argument must be given. .. rust:enum:: pub enum ContentRule Whether a directive takes content. .. rubric:: Variants .. rust:variant:: None Content is refused. .. rust:variant:: Optional Content may be given. .. rust:variant:: Required Content must be given. .. rust:enum:: pub enum OptType The type of an option's value, checked before the directive runs. .. rubric:: Variants .. rust:variant:: Flag No value. .. rust:variant:: Text Any text, possibly empty. .. rust:variant:: TextRequired Non-empty text. .. rust:variant:: Int A signed integer. .. rust:variant:: NonnegInt A nonnegative integer. .. rust:variant:: PosInt A positive integer. .. rust:variant:: OptInt A nonnegative integer or nothing. .. rust:variant:: Length A CSS length (``12px``, ``3em``, a bare number). .. rust:variant:: LengthPercent A length or a percentage. .. rust:variant:: Figwidth A length, a percentage, or ``image``. .. rust:variant:: Percentage A percentage (with or without "%"). .. rust:variant:: Class Class names. .. rust:variant:: Name A reference name (non-empty). .. rust:variant:: Choice One of ``OptSpec::choices``. .. rust:variant:: Encoding An encoding name. .. rust:variant:: Char One character, ``tab``, ``space``, or a character code. .. rust:variant:: Widths ``auto``, ``grid``, or positive integers. .. rust:variant:: Path A path (non-empty). .. rubric:: Traits .. rust:trait:: pub trait Extension A dialect's directives, roles, and hooks. Methods take ``&self``: a dialect keeps its per-document state in cells, because handlers run re-entrantly (a directive's content holds more directives). .. rust:method:: fn directive(&self, name: &str) -> Option> Returns the handler of directive ``name``, or ``None`` for one the dialect does not define (the standard directives are consulted next). .. rust:method:: fn run_directive(&self, p: &mut Parser<'_, '_>, d: &Directive<'_>) -> Result<(), Fail> :provided: Runs a checked directive whose handler ``directive`` returned (``d.handler()``). Problems are reported; only a builder failure is an ``Err``. .. rust:method:: fn role(&self, _ctx: &mut ReadContext<'_>, _call: &RoleCall<'_>) -> bool :provided: Handles interpreted text before the document's and the standard roles: emits nodes through ``ctx.b`` and returns true, or returns false for a role it does not know. .. rust:method:: fn begin(&self, _p: &mut Parser<'_, '_>) -> Result<(), Fail> :provided: Runs before the main source's blocks. .. rust:method:: fn has_prologue(&self) -> bool :provided: Tells whether the dialect has a prologue (``prologue``). With one, the main source's leading field lines are read first, on their own, as Sphinx inserts rst_prolog after a document's bibliographic fields. .. rust:method:: fn prologue(&self, _p: &mut Parser<'_, '_>) -> Result<(), Fail> :provided: Runs after the main source's leading field lines (see ``has_prologue``). .. rust:method:: fn end(&self, _p: &mut Parser<'_, '_>) -> Result<(), Fail> :provided: Runs after the main source's blocks, before sections close (an epilogue). .. rust:method:: fn substitution(&self, _name: &str) -> Option :provided: Supplies a default substitution, such as Sphinx's ``|version|``: resolution asks it for every reference whose name no definition in the document has. .. rust:trait:: pub trait Host The host markup's side of hosted directives. Lines are views of the current source (``Parser::src``), as the block parser's are, so every node keeps exact spans. Methods take ``&self``: a host keeps its parser state in cells, as they run re-entrantly. .. rust:method:: fn body(&self, p: &mut Parser<'_, '_>, lines: &[Line<'_>], sections: bool, each: Option) -> Result<(), Fail> Parses nested body content of the open node; ``sections`` allows headings to make sections, and ``each``, when set, gives these classes to every top-level element (the class directive). .. rust:method:: fn inline(&self, p: &mut Parser<'_, '_>, lines: &[Line<'_>]) -> Result<(), Fail> Parses inline content of the open node. .. rust:method:: fn items<'s>(&self, p: &mut Parser<'_, '_>, lines: &[Line<'s>]) -> Option>> Splits lines that hold one bullet list, in the host's list syntax, into its items (list-table); ``None`` when the lines are not one bullet list. .. rubric:: Functions .. rust:function:: pub fn find_handler<'h>(table: &'h [DirectiveHandler<'h>], name: &str) -> Option<&'h DirectiveHandler<'h>> Returns the handler of ``table`` named ``name``, compared case-insensitively. .. rust:function:: pub fn embed_begin(ctx: &mut ReadContext<'_>, settings: &Settings, ext: Option<&dyn Extension>) -> Result Prepares the reader for a host that reads the main source itself: the state for ``ctx`` with ``settings``, after the dialect's begin hook ran. The host views the state as a parser (``ReaderState::parser``) for every call and ends with ``Parser::embed_end``. Fails only when the builder fails. .. rust:function:: pub fn path_of(lines: &[Line<'_>]) -> String Joins path lines without white space, as the specification treats paths. .. rust:function:: pub fn dedent(lines: &mut [Line<'_>]) Strips the least indentation of the non-blank lines, in place. .. rust:function:: pub fn expand_views<'s>(views: &[LineView<'s>], tab: usize, buf: &'s mut String) -> Vec> Makes lines of a host's views of source text, expanding tabs into ``buf`` as ``split_lines`` does. .. rust:function:: pub fn indent_of(s: &str) -> usize Counts the spaces ``s`` starts with. .. rust:function:: pub fn join_lines<'s>(lines: &[Line<'s>], sep: &str) -> Cow<'s, str> Joins the lines' text with ``sep``: borrowed for a single line, else a copy. .. rust:function:: pub fn trim_blank_end<'l, 's>(lines: &'l [Line<'s>]) -> &'l [Line<'s>] Returns ``lines`` without trailing blank lines. .. rust:function:: pub fn trim_blank_start<'l, 's>(lines: &'l [Line<'s>]) -> &'l [Line<'s>] Returns ``lines`` without leading blank lines. .. rust:function:: pub fn bullet_width(t: &str) -> usize Returns the byte length of a bullet that starts ``t``, or 0. .. rust:function:: pub fn option_problem(s: &OptSpec, v: &str) -> Option<&'static str> Checks value ``v`` against the option's type: ``None`` when it is valid, else why not. .. rust:function:: pub fn read(ctx: &mut ReadContext<'_>) -> Result<(), Fail> Reads ``ctx.source`` as reStructuredText into ``ctx.b`` (``guidedoc::ReadFn``). Problems go to the reports; it fails when the builder fails (a limit, capacity) or reference resolution does. .. rust:function:: pub fn read_inline(ctx: &mut ReadContext<'_>, span: SourceSpan) -> Result<(), Fail> Parses a span of ``ctx.source`` as inline content of the builder's open node, as Sphinx parses a translated message (``guidedoc::ReadInlineFn``). Each line's leading white space is dropped. References are left for the caller to resolve. .. rust:function:: pub fn read_inline_with(ctx: &mut ReadContext<'_>, span: SourceSpan, settings: &Settings, ext: Option<&dyn Extension>) -> Result<(), Fail> ``read_inline`` with explicit settings and a dialect's roles. .. rust:function:: pub fn read_with(ctx: &mut ReadContext<'_>, settings: &Settings, ext: Option<&dyn Extension>) -> Result<(), Fail> Reads ``ctx.source`` with explicit settings and a dialect's handlers (the Sphinx layer's entry point). The extension's hooks run at their points of the read: begin, prologue (after the leading field lines), end, then resolution with its default substitutions. .. rust:function:: pub const fn reader() -> Reader :const: Returns the "rst" reader descriptor, for a ``guidedoc::Registry``. .. rust:function:: pub fn default_settings() -> Settings Returns Docutils' defaults: bibliographic fields on, everything else off or empty (``Settings::default()``). .. rust:function:: pub const fn choice(name: &'static str, choices: &'static str) -> OptSpec :const: Shorthand for a choice option. .. rust:function:: pub fn equal_fold(a: &str, b: &str) -> bool Compares ASCII case-insensitively, as directive and role names are compared. .. rust:function:: pub fn find_standard_directive(name: &str) -> Option> Returns the standard directive called ``name``, compared case-insensitively, as the handler the reader checks it with; ``None`` for any other name. .. rust:function:: pub const fn opt(name: &'static str, kind: OptType) -> OptSpec :const: Shorthand for an option specification without choices. .. rust:function:: pub fn standard_directives() -> impl Iterator> Returns the standard (Docutils) directives in the order the reader lists them, as the handlers the reader checks them with. The ``tag`` of each is its index in that order. A dialect such as the Sphinx layer may redefine some of them. .. rust:function:: pub fn column_width(s: &str) -> usize Returns the display width of ``s`` in columns, as Docutils measures a section title against its underline: East Asian wide and fullwidth characters count two columns, combining marks none, every other character one. .. rubric:: Constants .. rust:const:: pub const CONFORMANCE: Conformance = Conformance::Partial How complete the reader is. .. rust:const:: pub const VERSION: &str = env!("CARGO_PKG_VERSION") The reader's version: the project version.