guidedoc_commonmark¶
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.
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"));
Structs
- pub struct guidedoc_commonmark::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.Fields
- pub name: &'d str¶
-
The name, as written.
- pub name_span: SourceSpan¶
-
Where the name is.
- pub span: SourceSpan¶
-
The whole directive.
- pub options: Vec<DirectiveOption<'d>>¶
-
The options, in order.
- pub sections: bool¶
-
The directive stands where sections are allowed.
Implementations
- pub struct guidedoc_commonmark::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;
spanis where the value is written.Fields
- pub name: &'d str¶
-
The option’s name.
- pub span: SourceSpan¶
-
Where it is written.
Implementations
- impl DirectiveOption<'_>
- pub struct guidedoc_commonmark::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.
Fields
- pub argument: bool¶
-
It takes an argument.
- pub options: bool¶
-
It has options; without, an option block stays content.
Trait Implementations
- impl Default for DirectiveShape
-
- fn default() -> Self
-
An argument and options, the shape assumed when the extension does not say.
- pub struct guidedoc_commonmark::ListItems<'l>¶
-
The items of a bullet list, as
Host::list_itemssplits it: each item’s content lines, and the index of its first line in the given lines.Fields
- pub starts: Vec<usize>¶
-
Where each item starts in the given lines.
- pub struct guidedoc_commonmark::Role<'r>¶
-
A role,
{name}content``.lineshold the whole construct split at line breaks;contentis the range of the content in the lines joined by “\n”.Fields
- pub name: &'r str¶
-
The role’s name, as written.
- pub content: Range<usize>¶
-
The content’s range in the joined lines.
- pub span: SourceSpan¶
-
The whole construct.
Implementations
- pub struct guidedoc_commonmark::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.Implementations
- impl<'h> Detached<'h>
-
- pub fn attach<'a, R>(&mut self, ctx: &mut ReadContext<'a>, f: impl FnOnce(&mut Host<'_, 'a>) -> R) -> R¶
-
Runs
fwith a host made ofctxand this state, asHost::detachtook it apart; the state takes back whatfchanged.
- pub fn set_extension_state<T: Any>(&mut self, state: T)¶
-
Stores the extension’s per-read state, as
Host::set_extension_state.
Trait Implementations
- impl std::fmt::Debug for Detached<'_>
-
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
- pub struct guidedoc_commonmark::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.Implementations
- impl<'h, 'a> Host<'h, 'a>
-
- pub fn parse_body(&mut self, lines: &[Line<'_>], source: SourceId, sections: bool, classes: Option<Text>) -> Result<(), Fail>¶
-
Parses
linesofsourceas Markdown body content of the builder’s open node.sectionslets 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.
- pub fn parse_inline(&mut self, lines: &[Line<'_>], source: SourceId) -> Result<(), Fail>¶
-
Parses
linesofsourceas Markdown inline content of the builder’s open node.
- pub fn context(&mut self) -> &mut ReadContext<'a>¶
-
Returns the read context, for handlers that build nodes or include sources.
- pub fn is_myst(&self) -> bool¶
-
Tells whether the MyST syntax is on (the “myst” reader).
- 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.
- 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.
- pub fn list_items<'l>(&mut self, lines: &[Line<'l>], source: SourceId) -> Result<Option<ListItems<'l>>, Fail>¶
-
Splits
linesthat 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.
- pub fn set_extension_state<T: Any>(&mut self, state: T)¶
-
Stores the extension’s per-read state, replacing any earlier state.
- impl<'h, 'a> Host<'h, 'a>
-
- pub fn detach<R>(&mut self, f: impl FnOnce(&mut ReadContext<'a>, &mut Detached<'h>) -> R) -> R¶
-
Runs
fwith the read context and the rest of the host apart; the host is whole again afterwards (with whatfchanged in either part).
Trait Implementations
- impl std::fmt::Debug for Host<'_, '_>
-
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
- pub struct guidedoc_commonmark::Meta¶
-
One HTML meta tag: the key as MyST writes it (“description lang=en”, “http-equiv=Content-Type”, “keywords”) and its content.
Fields
- pub struct guidedoc_commonmark::Settings¶
-
The “myst” reader’s settings, named as myst-parser’s
myst_*configuration values without the prefix. They reach the reader throughReadOptions::extension, made withguidedoc::read_extension(&settings); no extension meansSettings::default(). The “commonmark” reader (pure CommonMark) takes none. Start fromSettings::default(), since several defaults are not zero:use guidedoc_commonmark::{Settings, SyntaxExtension}; let mut settings = Settings::default(); settings.enable_extensions.insert(SyntaxExtension::Deflist); settings.heading_anchors = 2;
Fields
- pub extension: Option<Arc<dyn Extension>>¶
-
Directive and role handlers (the Sphinx layer provides them);
Nonemeans none, and directives are then reported as needing them.
- 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.
- pub enable_extensions: SyntaxExtensions¶
-
myst_enable_extensions: the optional syntax. Default: dollarmath.
- pub disable_syntax: Vec<String>¶
-
myst_disable_syntax: markdown-it rule names whose syntax is not parsed, such as “emphasis”, “table”, “html_block” (see
Rule::named). Unknown names warn.
- pub url_schemes: Option<Vec<String>>¶
-
myst_url_schemes: schemes of
[text](scheme:...)links that are external; other destinations are cross-references.Nonerecognizes every scheme. Default http, https, mailto, and ftp.
- pub linkify_fuzzy_links: bool¶
-
myst_linkify_fuzzy_links: linkify recognizes URLs without a scheme. Default true.
- pub heading_anchors: usize¶
-
myst_heading_anchors: headings up to this level get a GitHub-style slug anchor that
[](#slug)reaches. 0 means none.
- 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.
- pub substitutions: Vec<Substitution>¶
-
myst_substitutions: global substitutions; front matter overrides them.
- pub sub_delimiters: [u8; 2]¶
-
myst_sub_delimiters: the characters doubled around substitution references. Default
{and}, giving{{ name }}.
- pub html_meta: Vec<Meta>¶
-
myst_html_meta: HTML meta tags for every document; front matter html_meta overrides entries with the same key.
- pub footnote_transition: bool¶
-
myst_footnote_transition: a transition of class “footnotes” precedes the footnotes at the end of the document. Default true.
- pub dmath_allow_labels: bool¶
-
myst_dmath_allow_labels:
$$...$$ (label). Default true.
- pub dmath_allow_space: bool¶
-
myst_dmath_allow_space: inline math may start or end with a space. Default true.
- pub dmath_allow_digits: bool¶
-
myst_dmath_allow_digits: inline math may follow or precede a digit. Default true.
- pub dmath_double_inline: bool¶
-
myst_dmath_double_inline:
$$...$$inside a paragraph. Default false.
- pub words_per_minute: usize¶
-
myst_words_per_minute: for the wordcount-minutes substitution. Default 200.
- pub env_config: Vec<Substitution>¶
-
Configuration values substitutions reach as env.config.<name>.
- pub today: String¶
-
The
{sub-ref}today: the project’s formatted date; empty meansReadOptions::today.
Trait Implementations
- impl fmt::Debug for Settings
-
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
- pub struct guidedoc_commonmark::Substitution¶
-
A substitution: a name and its Markdown value. Front matter mappings become dotted names (“key.sub”).
Fields
Implementations
- impl Substitution
-
- pub fn new(name: &str, value: &str) -> Substitution¶
-
Makes a substitution from borrowed text.
- pub struct guidedoc_commonmark::SyntaxExtensions(_)¶
-
A set of optional syntax extensions.
Implementations
- impl SyntaxExtensions
-
- pub const NONE: SyntaxExtensions = SyntaxExtensions(0)¶
-
No extension.
- pub const ALL: SyntaxExtensions = SyntaxExtensions((1 << 12) - 1)¶
-
Every extension.
- pub const fn of(list: &[SyntaxExtension]) -> SyntaxExtensions¶
-
Returns the set holding
list.
- pub const fn has(self, e: SyntaxExtension) -> bool¶
-
Tells whether
eis in the set.
- pub fn insert(&mut self, e: SyntaxExtension)¶
-
Adds
e.
- pub fn remove(&mut self, e: SyntaxExtension)¶
-
Removes
e.
- pub const fn is_empty(self) -> bool¶
-
Tells whether the set is empty.
Enums
- pub enum guidedoc_commonmark::DirectiveResult¶
-
What became of a directive a handler was offered.
Variants
- Ran¶
-
It ran.
- Unknown¶
-
The handler does not know the name; the reader reports it.
- Failed¶
-
The handler refused the directive and reported why.
- pub enum guidedoc_commonmark::Rule¶
-
A syntax element
disable_syntaxcan turn off, by markdown-it’s rule name.Variants
- Table¶
- Code¶
- Fence¶
- Blockquote¶
- Hr¶
- List¶
- Reference¶
- HtmlBlock¶
- Heading¶
- Lheading¶
- Emphasis¶
- Backticks¶
- Link¶
- Image¶
- Autolink¶
- HtmlInline¶
- Entity¶
- Escape¶
- Newline¶
- FrontMatter¶
- MystTarget¶
- MystLineComment¶
- MystBlockBreak¶
- MystRole¶
- MathBlock¶
- MathInline¶
- FootnoteDef¶
- FootnoteRef¶
- MystDirective¶
-
Not a markdown-it rule:
{name}fences (off withcommonmark_only).
Implementations
- pub enum guidedoc_commonmark::SyntaxExtension¶
-
An entry of myst_enable_extensions.
Variants
- Amsmath¶
- ColonFence¶
- Deflist¶
- Dollarmath¶
- Fieldlist¶
- HtmlAdmonition¶
- HtmlImage¶
- Linkify¶
- Replacements¶
- Smartquotes¶
- Substitution¶
- Tasklist¶
Implementations
- impl SyntaxExtension
-
- pub const ALL: [SyntaxExtension; 12]¶
-
Every extension, in declaration order.
- pub fn name(self) -> &'static str¶
-
Returns its name in myst_enable_extensions (“colon_fence”).
- pub fn named(name: &str) -> Option<SyntaxExtension>¶
-
Finds an extension by its myst_enable_extensions name.
Traits
- pub trait guidedoc_commonmark::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 inHost::set_extension_state, typically frombegin. Names arrive as written; compare them case-insensitively, as myst-parser does.- fn shape(&self, h: &mut Host<'_, '_>, name: &str) -> Option<DirectiveShape>¶
-
Describes directive
name;Nonefor a directive the extension does not know, which the reader reports.
- fn directive(&self, h: &mut Host<'_, '_>, d: &Directive<'_>) -> Result<DirectiveResult, Fail>¶
-
Runs a parsed directive. Its lines borrow the reader’s buffers for the call.
- fn role(&self, h: &mut Host<'_, '_>, r: &Role<'_>) -> Result<bool, Fail>¶
-
Runs a role;
Ok(false)for a role it does not know, which the reader reports and keeps as text.
- fn table(&self, h: &mut Host<'_, '_>, table: NodeId, span: SourceSpan, columns: usize) -> Result<bool, Fail>¶
-
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.
- fn begin(&self, h: &mut Host<'_, '_>) -> Result<(), Fail>¶
-
Runs before the document’s blocks (and before inline content read alone).
Functions
- pub fn guidedoc_commonmark::read(ctx: &mut ReadContext<'_>) -> Result<(), Fail>¶
-
Reads
ctx.sourceas pure CommonMark 0.31.2. Settings in the read options are refused withInvalidInput; problems go to the reports; a builder failure (limits, capacity) is returned.
- pub fn guidedoc_commonmark::read_myst(ctx: &mut ReadContext<'_>) -> Result<(), Fail>¶
-
Reads
ctx.sourceas MyST Markdown with theSettingsof the read options. Settings of another type are refused withInvalidInput.
- pub fn guidedoc_commonmark::read_inline(ctx: &mut ReadContext<'_>, span: SourceSpan) -> Result<(), Fail>¶
-
Parses
spanofctx.sourceas 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.
- pub fn guidedoc_commonmark::read_myst_inline(ctx: &mut ReadContext<'_>, span: SourceSpan) -> Result<(), Fail>¶
-
read_inlinefor MyST, with the settings of the read options (roles included).
Type Aliases
- pub type guidedoc_commonmark::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.
Constants
- pub const guidedoc_commonmark::DEFAULT_URL_SCHEMES: [&str; 4] = ["http", "https", "mailto", "ftp"]¶
-
The URL schemes myst-parser 0.16.1 links by default.
- pub const guidedoc_commonmark::VERSION: &str = "0.31.2"¶
-
The CommonMark version the “commonmark” reader implements.
- pub const guidedoc_commonmark::MYST_VERSION: &str = "0.16.1"¶
-
The myst-parser version the “myst” reader follows, with the differences docs/manual/internals/commonmark-conformance.rst documents.