guidedoc_commonmark =================== .. rust:crate:: guidedoc_commonmark :synopsis: Markdown for Guidedoc, as two readers with distinct ids: "commonmark" is pure CommonMark 0.31.2 and takes no settings; "myst" is the MyST Markdown that Sphinx projects write (myst-parser 0.16.1): directives, roles, targets, comments, front matter, footnotes, GFM tables, and the optional syntax Settings::enable_extensions turns on. Markdown for Guidedoc, as two readers with distinct ids: "commonmark" is pure CommonMark 0.31.2 and takes no settings; "myst" is the MyST Markdown that Sphinx projects write (myst-parser 0.16.1): directives, roles, targets, comments, front matter, footnotes, GFM tables, and the optional syntax ``Settings::enable_extensions`` turns on. Block structure is parsed line by line into a skeleton; link reference definitions are collected over the whole document; then the skeleton is emitted in preorder, with inline content parsed per paragraph and heading. Directive content is parsed the same way when a handler asks for it (``Extension``, ``Host::parse_body``), so a parse works on line views of any source. .. code-block:: rust use guidedoc::{Workspace, default_request, dump_to_string, read_document}; let mut ws = Workspace::new(); let request = default_request("a.md", "# Hi *there*\n", "commonmark", "html"); let doc = read_document(&mut ws, &guidedoc_commonmark::READER, &request).unwrap(); assert!(dump_to_string(doc).contains("emphasis")); .. rubric:: Structs .. rust:struct:: pub struct Directive<'d> A directive the reader has split into its parts. Lines are views of ``source`` (or of the reader's copies of it); they borrow the reader for the call. .. rubric:: Fields .. rust:field:: pub name: &'d str The name, as written. .. rust:field:: pub name_span: SourceSpan Where the name is. .. rust:field:: pub span: SourceSpan The whole directive. .. rust:field:: pub source: SourceId The source the lines belong to. .. rust:field:: pub argument: Vec> The argument; empty when there is none. .. rust:field:: pub options: Vec> The options, in order. .. rust:field:: pub content: Vec> The content after the options. .. rust:field:: pub sections: bool The directive stands where sections are allowed. .. rubric:: Implementations .. rust:impl:: impl Directive<'_> :noindex: :for: Directive<'_> .. rust:method:: pub fn option(&self, name: &str) -> Option<&DirectiveOption<'_>> Returns the option named ``name``. .. rust:method:: pub fn argument_text(&self) -> String Returns the argument's lines joined by "\\n". .. rust:struct:: pub struct DirectiveOption<'d> One directive option: its name and value lines. A value written as a YAML scalar has its quoting and folding processed, so its lines may not be views of the source; ``span`` is where the value is written. .. rubric:: Fields .. rust:field:: pub name: &'d str The option's name. .. rust:field:: pub value: Vec> Its value; empty for a flag. .. rust:field:: pub span: SourceSpan Where it is written. .. rubric:: Implementations .. rust:impl:: impl DirectiveOption<'_> :noindex: :for: DirectiveOption<'_> .. rust:method:: pub fn text(&self) -> String Returns the value's lines joined by "\\n". .. rust:struct:: pub struct DirectiveShape How a directive takes its first line: as an argument, or (without arguments) as the first line of content; and whether it takes options at all. .. rubric:: Fields .. rust:field:: pub argument: bool It takes an argument. .. rust:field:: pub options: bool It has options; without, an option block stays content. .. rubric:: Trait Implementations .. rust:impl:: impl Default for DirectiveShape :noindex: :for: DirectiveShape :trait: Default .. rust:method:: fn default() -> Self :noindex: An argument and options, the shape assumed when the extension does not say. .. rust:struct:: pub struct ListItems<'l> The items of a bullet list, as ``Host::list_items`` splits it: each item's content lines, and the index of its first line in the given lines. .. rubric:: Fields .. rust:field:: pub items: Vec>> Each item's content lines, cut at its content column. .. rust:field:: pub starts: Vec Where each item starts in the given lines. .. rust:struct:: pub struct Role<'r> A role, ``{name}``\ content\`\`. ``lines`` hold the whole construct split at line breaks; ``content`` is the range of the content in the lines joined by "\\n". .. rubric:: Fields .. rust:field:: pub name: &'r str The role's name, as written. .. rust:field:: pub lines: Vec> The whole construct, as lines. .. rust:field:: pub content: Range The content's range in the joined lines. .. rust:field:: pub span: SourceSpan The whole construct. .. rust:field:: pub source: SourceId The source the lines belong to. .. rubric:: Implementations .. rust:impl:: impl Role<'_> :noindex: :for: Role<'_> .. rust:method:: pub fn content_text(&self) -> String Returns the content: the lines joined by "\\n", cut to ``content``. .. rust:struct:: pub struct Detached<'h> A host without its read context: everything else of the read's state. A handler that lends the context to another parser (the Sphinx layer's embedded reStructuredText parser) uses it to parse nested Markdown with that parser's context (``Detached::attach``), so the two readers never hold the context at once. .. rubric:: Implementations .. rust:impl:: impl<'h> Detached<'h> :noindex: :for: Detached<'h> .. rust:method:: pub fn attach<'a, R>(&mut self, ctx: &mut ReadContext<'a>, f: impl FnOnce(&mut Host<'_, 'a>) -> R) -> R Runs ``f`` with a host made of ``ctx`` and this state, as ``Host::detach`` took it apart; the state takes back what ``f`` changed. .. rust:method:: pub fn set_extension_state(&mut self, state: T) Stores the extension's per-read state, as ``Host::set_extension_state``. .. rust:method:: pub fn extension_state(&mut self) -> Option<&mut T> Returns the extension's per-read state, as ``Host::extension_state``. .. rubric:: Trait Implementations .. rust:impl:: impl std::fmt::Debug for Detached<'_> :noindex: :for: Detached<'_> :trait: std::fmt::Debug .. rust:method:: fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result :noindex: .. rust:struct:: pub struct Host<'h, 'a> The reader's state for one read. Directive and role handlers receive it and use its public methods (see ``extension.rs``) to build nodes and parse nested content. .. rubric:: Implementations .. rust:impl:: impl<'h, 'a> Host<'h, 'a> :noindex: :for: Host<'h, 'a> .. rust:method:: pub fn parse_body(&mut self, lines: &[Line<'_>], source: SourceId, sections: bool, classes: Option) -> Result<(), Fail> Parses ``lines`` of ``source`` as Markdown body content of the builder's open node. ``sections`` lets headings open sections, as at the top of a document; ``classes``, when set, go to every top-level element. Included sources lose their front matter, as MyST ignores it. .. rust:method:: pub fn parse_inline(&mut self, lines: &[Line<'_>], source: SourceId) -> Result<(), Fail> Parses ``lines`` of ``source`` as Markdown inline content of the builder's open node. .. rust:method:: pub fn context(&mut self) -> &mut ReadContext<'a> Returns the read context, for handlers that build nodes or include sources. .. rust:method:: pub fn builder(&mut self) -> &mut Builder<'a> Returns the builder of the read. .. rust:method:: pub fn settings(&self) -> &'h Settings Returns the reader's settings. .. rust:method:: pub fn is_myst(&self) -> bool Tells whether the MyST syntax is on (the "myst" reader). .. rust:method:: pub fn set_classes_for_next(&mut self, classes: Text) Gives ``classes`` (pool text) to the next block the reader emits, as Docutils' class directive without content does. .. rust:method:: pub fn include_paths(&mut self, images: bool, docs: &str) -> (bool, String) Sets MyST's include options ``:relative-images:`` and ``:relative-docs:`` for the content of the include directive being run; returns the previous values, which the handler restores afterwards. .. rust:method:: pub fn list_items<'l>(&mut self, lines: &[Line<'l>], source: SourceId) -> Result>, Fail> Splits ``lines`` that hold one bullet list into the content lines of its items (for list-table). ``Ok(None)`` when the lines are anything but one bullet list. .. rust:method:: pub fn set_extension_state(&mut self, state: T) Stores the extension's per-read state, replacing any earlier state. .. rust:method:: pub fn extension_state(&mut self) -> Option<&mut T> Returns the extension's per-read state, when it is a ``T``. .. rust:method:: pub fn name_text(&mut self, s: &str) -> Result Writes a reference name into the text pool, case-folded with white space collapsed, as targets and names are stored. .. rust:impl:: impl<'h, 'a> Host<'h, 'a> :noindex: :for: Host<'h, 'a> .. rust:method:: pub fn detach(&mut self, f: impl FnOnce(&mut ReadContext<'a>, &mut Detached<'h>) -> R) -> R Runs ``f`` with the read context and the rest of the host apart; the host is whole again afterwards (with what ``f`` changed in either part). .. rubric:: Trait Implementations .. rust:impl:: impl std::fmt::Debug for Host<'_, '_> :noindex: :for: Host<'_, '_> :trait: std::fmt::Debug .. rust:method:: fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result :noindex: .. rust:struct:: pub struct Meta One HTML meta tag: the key as MyST writes it ("description lang=en", "http-equiv=Content-Type", "keywords") and its content. .. rubric:: Fields .. rust:field:: pub key: String The key. .. rust:field:: pub content: String The content. .. rust:struct:: pub struct Settings The "myst" reader's settings, named as myst-parser's ``myst_*`` configuration values without the prefix. They reach the reader through ``ReadOptions::extension``, made with ``guidedoc::read_extension(&settings)``; no extension means ``Settings::default()``. The "commonmark" reader (pure CommonMark) takes none. Start from ``Settings::default()``, since several defaults are not zero: .. code-block:: rust use guidedoc_commonmark::{Settings, SyntaxExtension}; let mut settings = Settings::default(); settings.enable_extensions.insert(SyntaxExtension::Deflist); settings.heading_anchors = 2; .. rubric:: Fields .. rust:field:: pub extension: Option> Directive and role handlers (the Sphinx layer provides them); ``None`` means none, and directives are then reported as needing them. .. rust:field:: pub commonmark_only: bool myst_commonmark_only: CommonMark syntax only (no directives, roles, or other MyST syntax), but a document's tree as for MyST: headings make sections. .. rust:field:: pub enable_extensions: SyntaxExtensions myst_enable_extensions: the optional syntax. Default: dollarmath. .. rust:field:: pub disable_syntax: Vec myst_disable_syntax: markdown-it rule names whose syntax is not parsed, such as "emphasis", "table", "html_block" (see ``Rule::named``). Unknown names warn. .. rust:field:: pub url_schemes: Option> myst_url_schemes: schemes of ``[text](scheme:...)`` links that are external; other destinations are cross-references. ``None`` recognizes every scheme. Default http, https, mailto, and ftp. .. rust:field:: pub linkify_fuzzy_links: bool myst_linkify_fuzzy_links: linkify recognizes URLs without a scheme. Default true. .. rust:field:: pub heading_anchors: usize myst_heading_anchors: headings up to this level get a GitHub-style slug anchor that ``[](#slug)`` reaches. 0 means none. .. rust:field:: pub heading_slug_func: String myst_heading_slug_func names a Python callable and cannot be supported; a non-empty value is reported and the built-in slugs are used. .. rust:field:: pub substitutions: Vec myst_substitutions: global substitutions; front matter overrides them. .. rust:field:: pub sub_delimiters: [u8; 2] myst_sub_delimiters: the characters doubled around substitution references. Default ``{`` and ``}``, giving ``{{ name }}``. .. rust:field:: pub html_meta: Vec myst_html_meta: HTML meta tags for every document; front matter html_meta overrides entries with the same key. .. rust:field:: pub footnote_transition: bool myst_footnote_transition: a transition of class "footnotes" precedes the footnotes at the end of the document. Default true. .. rust:field:: pub dmath_allow_labels: bool myst_dmath_allow_labels: ``$$...$$ (label)``. Default true. .. rust:field:: pub dmath_allow_space: bool myst_dmath_allow_space: inline math may start or end with a space. Default true. .. rust:field:: pub dmath_allow_digits: bool myst_dmath_allow_digits: inline math may follow or precede a digit. Default true. .. rust:field:: pub dmath_double_inline: bool myst_dmath_double_inline: ``$$...$$`` inside a paragraph. Default false. .. rust:field:: pub words_per_minute: usize myst_words_per_minute: for the wordcount-minutes substitution. Default 200. .. rust:field:: pub docname: String The document's name ("usage/intro"), which substitutions reach as env.docname. .. rust:field:: pub env_config: Vec Configuration values substitutions reach as env.config.. .. rust:field:: pub today: String The ``{sub-ref}`` today: the project's formatted date; empty means ``ReadOptions::today``. .. rubric:: Trait Implementations .. rust:impl:: impl fmt::Debug for Settings :noindex: :for: Settings :trait: fmt::Debug .. rust:method:: fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result :noindex: .. rust:impl:: impl Default for Settings :noindex: :for: Settings :trait: Default .. rust:method:: fn default() -> Settings :noindex: myst-parser 0.16.1's defaults. .. rust:struct:: pub struct Substitution A substitution: a name and its Markdown value. Front matter mappings become dotted names ("key.sub"). .. rubric:: Fields .. rust:field:: pub name: String The name, as ``{{ name }}`` writes it. .. rust:field:: pub value: String The value, Markdown. .. rubric:: Implementations .. rust:impl:: impl Substitution :noindex: :for: Substitution .. rust:method:: pub fn new(name: &str, value: &str) -> Substitution Makes a substitution from borrowed text. .. rust:struct:: pub struct SyntaxExtensions(_) A set of optional syntax extensions. .. rubric:: Implementations .. rust:impl:: impl SyntaxExtensions :noindex: :for: SyntaxExtensions .. rust:associatedconst:: pub const NONE: SyntaxExtensions = SyntaxExtensions(0) No extension. .. rust:associatedconst:: pub const ALL: SyntaxExtensions = SyntaxExtensions((1 << 12) - 1) Every extension. .. rust:method:: pub const fn of(list: &[SyntaxExtension]) -> SyntaxExtensions :const: Returns the set holding ``list``. .. rust:method:: pub const fn has(self, e: SyntaxExtension) -> bool :const: Tells whether ``e`` is in the set. .. rust:method:: pub fn insert(&mut self, e: SyntaxExtension) Adds ``e``. .. rust:method:: pub fn remove(&mut self, e: SyntaxExtension) Removes ``e``. .. rust:method:: pub const fn is_empty(self) -> bool :const: Tells whether the set is empty. .. rubric:: Enums .. rust:enum:: pub enum DirectiveResult What became of a directive a handler was offered. .. rubric:: Variants .. rust:variant:: Ran It ran. .. rust:variant:: Unknown The handler does not know the name; the reader reports it. .. rust:variant:: Failed The handler refused the directive and reported why. .. rust:enum:: pub enum Rule A syntax element ``disable_syntax`` can turn off, by markdown-it's rule name. .. rubric:: Variants .. rust:variant:: Table .. rust:variant:: Code .. rust:variant:: Fence .. rust:variant:: Blockquote .. rust:variant:: Hr .. rust:variant:: List .. rust:variant:: Reference .. rust:variant:: HtmlBlock .. rust:variant:: Heading .. rust:variant:: Lheading .. rust:variant:: Emphasis .. rust:variant:: Backticks .. rust:variant:: Link .. rust:variant:: Image .. rust:variant:: Autolink .. rust:variant:: HtmlInline .. rust:variant:: Entity .. rust:variant:: Escape .. rust:variant:: Newline .. rust:variant:: FrontMatter .. rust:variant:: MystTarget .. rust:variant:: MystLineComment .. rust:variant:: MystBlockBreak .. rust:variant:: MystRole .. rust:variant:: MathBlock .. rust:variant:: MathInline .. rust:variant:: FootnoteDef .. rust:variant:: FootnoteRef .. rust:variant:: MystDirective Not a markdown-it rule: ``{name}`` fences (off with ``commonmark_only``). .. rubric:: Implementations .. rust:impl:: impl Rule :noindex: :for: Rule .. rust:associatedconst:: pub const ALL: [Rule; 29] Every rule, in declaration order. .. rust:method:: pub fn name(self) -> &'static str Returns markdown-it's name of the rule; "" for ``MystDirective``. .. rust:method:: pub fn named(name: &str) -> Option Finds a rule by its markdown-it name. .. rust:enum:: pub enum SyntaxExtension An entry of myst_enable_extensions. .. rubric:: Variants .. rust:variant:: Amsmath .. rust:variant:: ColonFence .. rust:variant:: Deflist .. rust:variant:: Dollarmath .. rust:variant:: Fieldlist .. rust:variant:: HtmlAdmonition .. rust:variant:: HtmlImage .. rust:variant:: Linkify .. rust:variant:: Replacements .. rust:variant:: Smartquotes .. rust:variant:: Substitution .. rust:variant:: Tasklist .. rubric:: Implementations .. rust:impl:: impl SyntaxExtension :noindex: :for: SyntaxExtension .. rust:associatedconst:: pub const ALL: [SyntaxExtension; 12] Every extension, in declaration order. .. rust:method:: pub fn name(self) -> &'static str Returns its name in myst_enable_extensions ("colon_fence"). .. rust:method:: pub fn named(name: &str) -> Option Finds an extension by its myst_enable_extensions name. .. rubric:: Traits .. rust:trait:: pub trait Extension: Send + Sync Directive and role handlers for the "myst" reader (``Settings::extension``). Every method borrows the host for the call; per-read state goes in ``Host::set_extension_state``, typically from ``begin``. Names arrive as written; compare them case-insensitively, as myst-parser does. .. rust:method:: fn shape(&self, h: &mut Host<'_, '_>, name: &str) -> Option :provided: Describes directive ``name``; ``None`` for a directive the extension does not know, which the reader reports. .. rust:method:: fn directive(&self, h: &mut Host<'_, '_>, d: &Directive<'_>) -> Result Runs a parsed directive. Its lines borrow the reader's buffers for the call. .. rust:method:: fn role(&self, h: &mut Host<'_, '_>, r: &Role<'_>) -> Result Runs a role; ``Ok(false)`` for a role it does not know, which the reader reports and keeps as text. .. rust:method:: fn table(&self, h: &mut Host<'_, '_>, table: NodeId, span: SourceSpan, columns: usize) -> Result :provided: Runs after the reader opens a Table node (``table``), before its rows, so a table directive around it can add its title and attributes; ``Ok(true)`` when it did, and the reader then adds no attributes of its own. .. rust:method:: fn begin(&self, h: &mut Host<'_, '_>) -> Result<(), Fail> :provided: Runs before the document's blocks (and before inline content read alone). .. rust:method:: fn end(&self, h: &mut Host<'_, '_>) -> Result<(), Fail> :provided: Runs after the document's blocks and footnotes. .. rust:method:: fn resolve(&self, h: &mut Host<'_, '_>) -> Result :provided: Links references, targets, and footnotes instead of the reader's own resolution; ``Ok(false)`` (the default) lets the reader resolve them. The Sphinx layer resolves as for reStructuredText. .. rubric:: Functions .. rust:function:: pub fn read(ctx: &mut ReadContext<'_>) -> Result<(), Fail> Reads ``ctx.source`` as pure CommonMark 0.31.2. Settings in the read options are refused with ``InvalidInput``; problems go to the reports; a builder failure (limits, capacity) is returned. .. rust:function:: pub fn read_myst(ctx: &mut ReadContext<'_>) -> Result<(), Fail> Reads ``ctx.source`` as MyST Markdown with the ``Settings`` of the read options. Settings of another type are refused with ``InvalidInput``. .. rust:function:: pub fn read_inline(ctx: &mut ReadContext<'_>, span: SourceSpan) -> Result<(), Fail> Parses ``span`` of ``ctx.source`` as CommonMark inline content of the builder's open node, for a translated message. Link reference definitions and footnotes of the surrounding document are not known to it. .. rust:function:: pub fn read_myst_inline(ctx: &mut ReadContext<'_>, span: SourceSpan) -> Result<(), Fail> ``read_inline`` for MyST, with the settings of the read options (roles included). .. rubric:: Type Aliases .. rust:type:: pub type Line<'s> = LineView<'s> A view of one input line: its text without the line break, and the source offset of its first byte. Handlers receive content as lines and pass nested content back so. .. rubric:: Constants .. rust:const:: pub const DEFAULT_URL_SCHEMES: [&str; 4] = ["http", "https", "mailto", "ftp"] The URL schemes myst-parser 0.16.1 links by default. .. rust:const:: pub const VERSION: &str = "0.31.2" The CommonMark version the "commonmark" reader implements. .. rust:const:: pub const MYST_VERSION: &str = "0.16.1" The myst-parser version the "myst" reader follows, with the differences docs/manual/internals/commonmark-conformance.rst documents. .. rust:const:: pub const READER: Reader The "commonmark" reader: pure CommonMark 0.31.2, headings without sections, no settings (any are refused with ``InvalidInput``). .. rust:const:: pub const MYST_READER: Reader The "myst" reader: MyST Markdown with the ``Settings`` the read options carry (``guidedoc::read_extension(&settings)``), or ``Settings::default()`` without any.