mirror of
https://github.com/typst/typst
synced 2025-05-18 11:05:28 +08:00
Changed rules of figures (#627)
This commit is contained in:
parent
52b92a9d35
commit
23a884a67f
@ -7,6 +7,7 @@ use crate::layout::{BlockElem, VElem};
|
|||||||
use crate::meta::{Refable, Supplement};
|
use crate::meta::{Refable, Supplement};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::text::TextElem;
|
use crate::text::TextElem;
|
||||||
|
use crate::visualize::ImageElem;
|
||||||
|
|
||||||
/// A figure with an optional caption.
|
/// A figure with an optional caption.
|
||||||
///
|
///
|
||||||
@ -174,10 +175,7 @@ impl Synthesize for FigureElem {
|
|||||||
Smart::Auto => self
|
Smart::Auto => self
|
||||||
.find_figurable(styles)
|
.find_figurable(styles)
|
||||||
.map(|elem| FigureKind::Elem(elem.func()))
|
.map(|elem| FigureKind::Elem(elem.func()))
|
||||||
.ok_or(
|
.unwrap_or_else(|| FigureKind::Elem(ImageElem::func())),
|
||||||
"unable to determine the figure's `kind`, please specify it manually",
|
|
||||||
)
|
|
||||||
.at(self.span())?,
|
|
||||||
Smart::Custom(kind) => kind,
|
Smart::Custom(kind) => kind,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -187,18 +185,34 @@ impl Synthesize for FigureElem {
|
|||||||
}
|
}
|
||||||
.unwrap_or_else(|| self.body());
|
.unwrap_or_else(|| self.body());
|
||||||
|
|
||||||
|
let numbering = self.numbering(styles);
|
||||||
|
|
||||||
// We get the supplement or `None`. The supplement must either be set
|
// We get the supplement or `None`. The supplement must either be set
|
||||||
// manually or the content identification must have succeeded.
|
// manually or the content identification must have succeeded.
|
||||||
let supplement = match self.supplement(styles) {
|
let supplement = match self.supplement(styles) {
|
||||||
Smart::Auto => match &kind {
|
Smart::Auto => match &kind {
|
||||||
FigureKind::Elem(func) => Content::new(*func)
|
FigureKind::Elem(func) => {
|
||||||
.with::<dyn LocalName>()
|
let elem = Content::new(*func).with::<dyn LocalName>().map(|c| {
|
||||||
.map(|c| TextElem::packed(c.local_name(TextElem::lang_in(styles))))
|
TextElem::packed(c.local_name(TextElem::lang_in(styles)))
|
||||||
|
});
|
||||||
|
|
||||||
|
if numbering.is_some() {
|
||||||
|
Some(elem
|
||||||
.ok_or("unable to determine the figure's `supplement`, please specify it manually")
|
.ok_or("unable to determine the figure's `supplement`, please specify it manually")
|
||||||
.at(self.span())?,
|
.at(self.span())?)
|
||||||
FigureKind::Name(_) => bail!(self.span(), "please specify the figure's supplement"),
|
} else {
|
||||||
|
elem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FigureKind::Name(_) => {
|
||||||
|
if numbering.is_some() {
|
||||||
|
bail!(self.span(), "please specify the figure's supplement")
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Smart::Custom(supp) => supp.resolve(vt, [content.into()])?,
|
Smart::Custom(supp) => Some(supp.resolve(vt, [content.into()])?),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Construct the figure's counter.
|
// Construct the figure's counter.
|
||||||
@ -210,9 +224,11 @@ impl Synthesize for FigureElem {
|
|||||||
)));
|
)));
|
||||||
|
|
||||||
self.push_kind(Smart::Custom(kind));
|
self.push_kind(Smart::Custom(kind));
|
||||||
self.push_supplement(Smart::Custom(Supplement::Content(supplement)));
|
self.push_numbering(numbering);
|
||||||
self.push_numbering(self.numbering(styles));
|
|
||||||
self.push_counter(Some(counter));
|
self.push_counter(Some(counter));
|
||||||
|
self.push_supplement(Smart::Custom(Supplement::Content(
|
||||||
|
supplement.unwrap_or_default(),
|
||||||
|
)));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user