summaryrefslogtreecommitdiff
path: root/library
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 /library
parent88cb8c26264713d6914c74226c962d4377b64668 (diff)
Fix figure detection
Diffstat (limited to 'library')
-rw-r--r--library/src/layout/table.rs6
-rw-r--r--library/src/meta/figure.rs24
-rw-r--r--library/src/text/raw.rs6
-rw-r--r--library/src/visualize/image.rs6
4 files changed, 9 insertions, 33 deletions
diff --git a/library/src/layout/table.rs b/library/src/layout/table.rs
index 29e2edb8..9cd18b56 100644
--- a/library/src/layout/table.rs
+++ b/library/src/layout/table.rs
@@ -319,8 +319,4 @@ impl LocalName for TableElem {
}
}
-impl Figurable for TableElem {
- fn priority(&self, _styles: StyleChain) -> isize {
- -1000
- }
-}
+impl Figurable for TableElem {}
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 {}
diff --git a/library/src/text/raw.rs b/library/src/text/raw.rs
index 4cc26fa6..db437481 100644
--- a/library/src/text/raw.rs
+++ b/library/src/text/raw.rs
@@ -244,11 +244,7 @@ impl LocalName for RawElem {
}
}
-impl Figurable for RawElem {
- fn priority(&self, _styles: StyleChain) -> isize {
- 500
- }
-}
+impl Figurable for RawElem {}
/// Highlight a syntax node in a theme by calling `f` with ranges and their
/// styles.
diff --git a/library/src/visualize/image.rs b/library/src/visualize/image.rs
index 917f483e..fc6aa651 100644
--- a/library/src/visualize/image.rs
+++ b/library/src/visualize/image.rs
@@ -144,11 +144,7 @@ impl LocalName for ImageElem {
}
}
-impl Figurable for ImageElem {
- fn priority(&self, _styles: StyleChain) -> isize {
- 1000
- }
-}
+impl Figurable for ImageElem {}
/// How an image should adjust itself to a given area.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Cast)]