From d14d1e867f83de631e7252ec5bdb2aa2dd870c8e Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 17 May 2023 12:55:25 +0200 Subject: Fix figure detection --- src/model/content.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/model') 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(); -- cgit v1.2.3