summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorMax <me@mkor.je>2024-09-02 12:58:33 +0000
committerGitHub <noreply@github.com>2024-09-02 12:58:33 +0000
commitc644dce81b1685383ee8d991a92991eb03f5e32e (patch)
treeefbbb92823928d5ae3f96dc14dde1f496fac080c /crates
parenta2628ac9702b085f3981c7306cee366717b0b77c (diff)
Add warnings when labels are ignored or unattached (#4783)
Diffstat (limited to 'crates')
-rw-r--r--crates/typst/src/eval/markup.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/crates/typst/src/eval/markup.rs b/crates/typst/src/eval/markup.rs
index 46abf8ce..a735bb8e 100644
--- a/crates/typst/src/eval/markup.rs
+++ b/crates/typst/src/eval/markup.rs
@@ -1,6 +1,8 @@
use crate::diag::{warning, SourceResult};
use crate::eval::{Eval, Vm};
-use crate::foundations::{Content, Label, NativeElement, Smart, Unlabellable, Value};
+use crate::foundations::{
+ Content, Label, NativeElement, Repr, Smart, Unlabellable, Value,
+};
use crate::math::EquationElem;
use crate::model::{
EmphElem, EnumItem, HeadingElem, LinkElem, ListItem, ParbreakElem, RefElem,
@@ -52,7 +54,20 @@ fn eval_markup<'a>(
if let Some(elem) =
seq.iter_mut().rev().find(|node| !node.can::<dyn Unlabellable>())
{
+ if elem.label().is_some() {
+ vm.engine.sink.warn(warning!(
+ elem.span(), "content labelled multiple times";
+ hint: "only the last label is used, the rest are ignored",
+ ));
+ }
+
*elem = std::mem::take(elem).labelled(label);
+ } else {
+ vm.engine.sink.warn(warning!(
+ expr.span(),
+ "label `{}` is not attached to anything",
+ label.repr()
+ ));
}
}
value => seq.push(value.display().spanned(expr.span())),