summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-05-17 12:55:25 +0200
committerLaurenz <laurmaedje@gmail.com>2023-05-17 12:55:25 +0200
commitd14d1e867f83de631e7252ec5bdb2aa2dd870c8e (patch)
tree0bd1b391c704ba2776810cfe6e6a5c4361263514 /src/model
parent88cb8c26264713d6914c74226c962d4377b64668 (diff)
Fix figure detection
Diffstat (limited to 'src/model')
-rw-r--r--src/model/content.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/model/content.rs b/src/model/content.rs
index 4eeecbd6..71a5cb84 100644
--- a/src/model/content.rs
+++ b/src/model/content.rs
@@ -373,6 +373,21 @@ impl Content {
results
}
+ /// Queries the content tree for the first element that match the given
+ /// selector.
+ ///
+ /// Elements produced in `show` rules will not be included in the results.
+ #[tracing::instrument(skip_all)]
+ pub fn query_first(&self, selector: Selector) -> Option<&Content> {
+ let mut result = None;
+ self.traverse(&mut |element| {
+ if result.is_none() && selector.matches(element) {
+ result = Some(element);
+ }
+ });
+ result
+ }
+
/// Extracts the plain text of this content.
pub fn plain_text(&self) -> EcoString {
let mut text = EcoString::new();