mirror of
https://github.com/typst/typst
synced 2025-08-04 02:07:56 +08:00
feat: improve error message for broken tags
This commit is contained in:
parent
d9356abb39
commit
55bc6abb60
@ -273,25 +273,35 @@ pub(crate) fn handle_end(
|
|||||||
// There are overlapping tags in the tag tree. Figure whether breaking
|
// There are overlapping tags in the tag tree. Figure whether breaking
|
||||||
// up the current tag stack is semantically ok.
|
// up the current tag stack is semantically ok.
|
||||||
let is_pdf_ua = gc.options.standards.config.validator() == Validator::UA1;
|
let is_pdf_ua = gc.options.standards.config.validator() == Validator::UA1;
|
||||||
let non_breakable = gc.tags.stack[idx + 1..]
|
let mut is_breakable = true;
|
||||||
.iter()
|
let mut non_breakable_span = Span::detached();
|
||||||
.find(|e| !e.kind.is_breakable(is_pdf_ua));
|
for e in gc.tags.stack[idx + 1..].iter() {
|
||||||
if let Some(entry) = non_breakable {
|
if e.kind.is_breakable(is_pdf_ua) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
is_breakable = false;
|
||||||
|
if !e.span.is_detached() {
|
||||||
|
non_breakable_span = e.span;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !is_breakable {
|
||||||
let validator = gc.options.standards.config.validator();
|
let validator = gc.options.standards.config.validator();
|
||||||
if is_pdf_ua {
|
if is_pdf_ua {
|
||||||
let ua1 = validator.as_str();
|
let ua1 = validator.as_str();
|
||||||
bail!(
|
bail!(
|
||||||
entry.span,
|
non_breakable_span,
|
||||||
"{ua1} error: invalid semantic structure, \
|
"{ua1} error: invalid semantic structure, \
|
||||||
this element's tag would be split up";
|
this element's tag would be split up";
|
||||||
hint: "maybe there is a `parbreak`, `colbreak`, or `pagebreak`"
|
hint: "maybe this is caused by a `parbreak`, `colbreak`, or `pagebreak`"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
bail!(
|
bail!(
|
||||||
entry.span,
|
non_breakable_span,
|
||||||
"invalid semantic structure, \
|
"invalid semantic structure, \
|
||||||
this element's tag would be split up";
|
this element's tag would be split up";
|
||||||
hint: "maybe there is a `parbreak`, `colbreak`, or `pagebreak`";
|
hint: "maybe this is caused by a `parbreak`, `colbreak`, or `pagebreak`";
|
||||||
hint: "disable tagged pdf by passing `--disable-pdf-tags`"
|
hint: "disable tagged pdf by passing `--disable-pdf-tags`"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user