pub struct BlockSelector<'a> { /* private fields */ }Expand description
A declarative selector for FindBlocks::find_blocks, mirroring the
selector hash of Asciidoctor’s find_by.
Build one with new and the builder methods. A field that is
left unset matches any block; when several fields are set they are combined
with logical AND.
| Method | Matches against |
|---|---|
context | IsBlock::resolved_context |
style | IsBlock::declared_style (see below) |
id | IsBlock::id |
role | membership in IsBlock::roles |
style matches declared_style,
which is the block’s resolved style and tracks Asciidoctor’s style in the
common cases — including variant blocks that report their style even in
shorthand form (e.g. an admonition written NOTE: matches style("NOTE")).
The one divergence: a style that masquerades as a built-in context (e.g.
[example], [sidebar]) is promoted to the block’s context, so match those
with context rather than style.
use asciidoc_parser::{
Parser,
blocks::{BlockSelector, FindBlocks},
};
let doc = Parser::default().parse("[#intro]\nHello.\n");
let block = doc.find_blocks(&BlockSelector::new().id("intro")).next();
assert!(block.is_some());Implementations§
Source§impl<'a> BlockSelector<'a>
impl<'a> BlockSelector<'a>
Sourcepub fn context(self, context: impl Into<Cow<'a, str>>) -> Self
pub fn context(self, context: impl Into<Cow<'a, str>>) -> Self
Restricts the match to blocks whose
resolved context equals context (e.g.
"listing", "section", "sidebar").
Sourcepub fn style(self, style: impl Into<Cow<'a, str>>) -> Self
pub fn style(self, style: impl Into<Cow<'a, str>>) -> Self
Restricts the match to blocks whose
declared style equals style (e.g.
"source", "verse", "NOTE").
Sourcepub fn id(self, id: impl Into<Cow<'a, str>>) -> Self
pub fn id(self, id: impl Into<Cow<'a, str>>) -> Self
Restricts the match to the block whose id equals id.
Sourcepub fn role(self, role: impl Into<Cow<'a, str>>) -> Self
pub fn role(self, role: impl Into<Cow<'a, str>>) -> Self
Restricts the match to blocks that carry role among their
roles.
Sourcepub fn traverse_documents(self, traverse_documents: bool) -> Self
pub fn traverse_documents(self, traverse_documents: bool) -> Self
Sets whether the traversal descends into AsciiDoc table cells (nested documents). Off by default.
Sourcepub fn matches(&self, block: &Block<'_>) -> bool
pub fn matches(&self, block: &Block<'_>) -> bool
Returns true if block satisfies every field this selector sets.
This does not consider traverse_documents,
which governs traversal rather than whether an individual block matches.
Trait Implementations§
Source§impl<'a> Clone for BlockSelector<'a>
impl<'a> Clone for BlockSelector<'a>
Source§fn clone(&self) -> BlockSelector<'a>
fn clone(&self) -> BlockSelector<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more