diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-05-17 12:55:25 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-05-17 12:55:25 +0200 |
| commit | d14d1e867f83de631e7252ec5bdb2aa2dd870c8e (patch) | |
| tree | 0bd1b391c704ba2776810cfe6e6a5c4361263514 /library/src/meta | |
| parent | 88cb8c26264713d6914c74226c962d4377b64668 (diff) | |
Fix figure detection
Diffstat (limited to 'library/src/meta')
| -rw-r--r-- | library/src/meta/figure.rs | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/library/src/meta/figure.rs b/library/src/meta/figure.rs index 2082701b..fe492238 100644 --- a/library/src/meta/figure.rs +++ b/library/src/meta/figure.rs @@ -178,7 +178,7 @@ impl Synthesize for FigureElem { // Determine the figure's kind. let kind = match self.kind(styles) { Smart::Auto => self - .find_figurable(styles) + .find_figurable() .map(|elem| FigureKind::Elem(elem.func())) .unwrap_or_else(|| FigureKind::Elem(ImageElem::func())), Smart::Custom(kind) => kind, @@ -324,22 +324,14 @@ impl Refable for FigureElem { impl FigureElem { /// Determines the type of the figure by looking at the content, finding all /// [`Figurable`] elements and sorting them by priority then returning the highest. - pub fn find_figurable(&self, styles: StyleChain) -> Option<Content> { - self.body() - .query(Selector::can::<dyn Figurable>()) - .into_iter() - .max_by_key(|elem| elem.with::<dyn Figurable>().unwrap().priority(styles)) - .cloned() + pub fn find_figurable(&self) -> Option<Content> { + self.body().query_first(Selector::can::<dyn Figurable>()).cloned() } /// Finds the element with the given function in the figure's content. /// Returns `None` if no element with the given function is found. pub fn find_of_elem(&self, func: ElemFunc) -> Option<Content> { - self.body() - .query(Selector::Elem(func, None)) - .into_iter() - .next() - .cloned() + self.body().query_first(Selector::Elem(func, None)).cloned() } /// Builds the supplement and numbering of the figure. Returns [`None`] if @@ -411,9 +403,5 @@ cast_to_value! { /// An element that can be auto-detected in a figure. /// -/// This trait is used to determine the type of a figure. The element chosen as -/// the figure's content is the figurable descendant with the highest priority. -pub trait Figurable: LocalName { - /// The priority of this element. - fn priority(&self, styles: StyleChain) -> isize; -} +/// This trait is used to determine the type of a figure. +pub trait Figurable: LocalName {} |
