Guidedog 설명서 1.0.0-beta.16
언어
이 페이지의 내용
Guidedog / 문서 1.0.0-beta.16

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 source: SourceId

The source the lines belong to.

pub argument: Vec<Line<'d>>

The argument; empty when there is none.

pub options: Vec<DirectiveOption<'d>>

The options, in order.

pub content: Vec<Line<'d>>

The content after the options.

pub sections: bool

The directive stands where sections are allowed.

Implementations

impl Directive<'_>
pub fn option(&self, name: &str) -> Option<&DirectiveOption<'_>>

Returns the option named name.

pub fn argument_text(&self) -> String

Returns the argument’s lines joined by “\n”.

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; span is where the value is written.

Fields

pub name: &'d str

The option’s name.

pub value: Vec<Line<'d>>

Its value; empty for a flag.

pub span: SourceSpan

Where it is written.

Implementations

impl DirectiveOption<'_>
pub fn text(&self) -> String

Returns the value’s lines joined by “\n”.

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_items splits it: each item’s content lines, and the index of its first line in the given lines.

Fields

pub items: Vec<Vec<Line<'l>>>

Each item’s content lines, cut at its content column.

pub starts: Vec<usize>

Where each item starts in the given lines.

pub struct guidedoc_commonmark::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”.

Fields

pub name: &'r str

The role’s name, as written.

pub lines: Vec<Line<'r>>

The whole construct, as lines.

pub content: Range<usize>

The content’s range in the joined lines.

pub span: SourceSpan

The whole construct.

pub source: SourceId

The source the lines belong to.

Implementations

impl Role<'_>
pub fn content_text(&self) -> String

Returns the content: the lines joined by “\n”, cut to content.

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 f with a host made of ctx and this state, as Host::detach took it apart; the state takes back what f changed.

pub fn set_extension_state<T: Any>(&mut self, state: T)

Stores the extension’s per-read state, as Host::set_extension_state.

pub fn extension_state<T: Any>(&mut self) -> Option<&mut T>

Returns the extension’s per-read state, as Host::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 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.

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.

pub fn context(&mut self) -> &mut ReadContext<'a>

Returns the read context, for handlers that build nodes or include sources.

pub fn builder(&mut self) -> &mut Builder<'a>

Returns the builder of the read.

pub fn settings(&self) -> &'h Settings

Returns the reader’s settings.

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

pub fn set_extension_state<T: Any>(&mut self, state: T)

Stores the extension’s per-read state, replacing any earlier state.

pub fn extension_state<T: Any>(&mut self) -> Option<&mut T>

Returns the extension’s per-read state, when it is a T.

pub fn name_text(&mut self, s: &str) -> Result<Text, Fail>

Writes a reference name into the text pool, case-folded with white space collapsed, as targets and names are stored.

impl<'h, 'a> Host<'h, 'a>
pub fn detach<R>(&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).

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

The key.

pub content: String

The content.

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

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); None means 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. None recognizes every scheme. Default http, https, mailto, and ftp.

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

The document’s name (“usage/intro”), which substitutions reach as env.docname.

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 means ReadOptions::today.

Trait Implementations

impl fmt::Debug for Settings
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl Default for Settings
fn default() -> Settings

myst-parser 0.16.1’s defaults.

pub struct guidedoc_commonmark::Substitution

A substitution: a name and its Markdown value. Front matter mappings become dotted names (“key.sub”).

Fields

pub name: String

The name, as {{ name }} writes it.

pub value: String

The value, Markdown.

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 e is 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_syntax can turn off, by markdown-it’s rule name.

Variants

Table
Code
Fence
Blockquote
Hr
List
Reference
HtmlBlock
Heading
Lheading
Emphasis
Backticks
Image
HtmlInline
Entity
Escape
Newline
FrontMatter
MystTarget
MystLineComment
MystBlockBreak
MystRole
MathBlock
MathInline
FootnoteDef
FootnoteRef
MystDirective

Not a markdown-it rule: {name} fences (off with commonmark_only).

Implementations

impl Rule
pub const ALL: [Rule; 29]

Every rule, in declaration order.

pub fn name(self) -> &'static str

Returns markdown-it’s name of the rule; “” for MystDirective.

pub fn named(name: &str) -> Option<Rule>

Finds a rule by its markdown-it name.

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 in Host::set_extension_state, typically from begin. 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; None for 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).

fn end(&self, h: &mut Host<'_, '_>) -> Result<(), Fail>

Runs after the document’s blocks and footnotes.

fn resolve(&self, h: &mut Host<'_, '_>) -> Result<bool, Fail>

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.

Functions

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

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

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

pub fn guidedoc_commonmark::read_myst_inline(ctx: &mut ReadContext<'_>, span: SourceSpan) -> Result<(), Fail>

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

pub const guidedoc_commonmark::READER: Reader

The “commonmark” reader: pure CommonMark 0.31.2, headings without sections, no settings (any are refused with InvalidInput).

pub const guidedoc_commonmark::MYST_READER: Reader

The “myst” reader: MyST Markdown with the Settings the read options carry (guidedoc::read_extension(&settings)), or Settings::default() without any.