summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Schmitz <tobiasschmitz2001@gmail.com>2025-06-26 18:50:43 +0200
committerTobias Schmitz <tobiasschmitz2001@gmail.com>2025-07-03 18:43:02 +0200
commit6ebe85d67877254683e8038ad7fbf262fd495636 (patch)
tree880d2e41d81a3ed5942270234e009665df06d7b9
parent76d09b567345c0eb8f51622064a998e4bcdde416 (diff)
fix: don't include outline title in TOC hierarchy
-rw-r--r--crates/typst-library/src/model/outline.rs19
-rw-r--r--crates/typst-pdf/src/tags.rs4
2 files changed, 20 insertions, 3 deletions
diff --git a/crates/typst-library/src/model/outline.rs b/crates/typst-library/src/model/outline.rs
index 9db263be..1e177130 100644
--- a/crates/typst-library/src/model/outline.rs
+++ b/crates/typst-library/src/model/outline.rs
@@ -273,6 +273,7 @@ impl Show for Packed<OutlineElem> {
let depth = self.depth(styles).unwrap_or(NonZeroUsize::MAX);
// Build the outline entries.
+ let mut entries = vec![];
for elem in elems {
let Some(outlinable) = elem.with::<dyn Outlinable>() else {
bail!(span, "cannot outline {}", elem.func().name());
@@ -281,10 +282,13 @@ impl Show for Packed<OutlineElem> {
let level = outlinable.level();
if outlinable.outlined() && level <= depth {
let entry = OutlineEntry::new(level, elem);
- seq.push(entry.pack().spanned(span));
+ entries.push(entry.pack().spanned(span));
}
}
+ // Wrap the entries into a marker for pdf tagging.
+ seq.push(OutlineBody::new(Content::sequence(entries)).pack());
+
Ok(Content::sequence(seq))
}
}
@@ -307,6 +311,19 @@ impl LocalName for Packed<OutlineElem> {
const KEY: &'static str = "outline";
}
+/// Only used to mark
+#[elem(Locatable, Show)]
+pub struct OutlineBody {
+ #[required]
+ body: Content,
+}
+
+impl Show for Packed<OutlineBody> {
+ fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> {
+ Ok(self.body.clone())
+ }
+}
+
/// Defines how an outline is indented.
#[derive(Debug, Clone, PartialEq, Hash)]
pub enum OutlineIndent {
diff --git a/crates/typst-pdf/src/tags.rs b/crates/typst-pdf/src/tags.rs
index d65e898c..8e41ea2f 100644
--- a/crates/typst-pdf/src/tags.rs
+++ b/crates/typst-pdf/src/tags.rs
@@ -11,7 +11,7 @@ use typst_library::foundations::{Content, LinkMarker, Packed, StyleChain};
use typst_library::introspection::Location;
use typst_library::layout::RepeatElem;
use typst_library::model::{
- Destination, FigureCaption, FigureElem, HeadingElem, Outlinable, OutlineElem,
+ Destination, FigureCaption, FigureElem, HeadingElem, Outlinable, OutlineBody,
OutlineEntry, TableCell, TableElem,
};
use typst_library::pdf::{ArtifactElem, ArtifactKind, PdfTagElem, PdfTagKind};
@@ -383,7 +383,7 @@ pub(crate) fn handle_start(gc: &mut GlobalContext, elem: &Content) {
// TODO: when targeting PDF 2.0 headings `> 6` are supported
_ => TagKind::H6(Some(name)).into(),
}
- } else if let Some(_) = elem.to_packed::<OutlineElem>() {
+ } else if let Some(_) = elem.to_packed::<OutlineBody>() {
push_stack(gc, loc, StackEntryKind::Outline(OutlineCtx::new()));
return;
} else if let Some(entry) = elem.to_packed::<OutlineEntry>() {