mirror of
https://github.com/typst/typst
synced 2025-07-27 14:27:56 +08:00
fix: don't include outline title in TOC hierarchy
This commit is contained in:
parent
76d09b5673
commit
6ebe85d678
@ -273,6 +273,7 @@ impl Show for Packed<OutlineElem> {
|
|||||||
let depth = self.depth(styles).unwrap_or(NonZeroUsize::MAX);
|
let depth = self.depth(styles).unwrap_or(NonZeroUsize::MAX);
|
||||||
|
|
||||||
// Build the outline entries.
|
// Build the outline entries.
|
||||||
|
let mut entries = vec![];
|
||||||
for elem in elems {
|
for elem in elems {
|
||||||
let Some(outlinable) = elem.with::<dyn Outlinable>() else {
|
let Some(outlinable) = elem.with::<dyn Outlinable>() else {
|
||||||
bail!(span, "cannot outline {}", elem.func().name());
|
bail!(span, "cannot outline {}", elem.func().name());
|
||||||
@ -281,10 +282,13 @@ impl Show for Packed<OutlineElem> {
|
|||||||
let level = outlinable.level();
|
let level = outlinable.level();
|
||||||
if outlinable.outlined() && level <= depth {
|
if outlinable.outlined() && level <= depth {
|
||||||
let entry = OutlineEntry::new(level, elem);
|
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))
|
Ok(Content::sequence(seq))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,6 +311,19 @@ impl LocalName for Packed<OutlineElem> {
|
|||||||
const KEY: &'static str = "outline";
|
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.
|
/// Defines how an outline is indented.
|
||||||
#[derive(Debug, Clone, PartialEq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Hash)]
|
||||||
pub enum OutlineIndent {
|
pub enum OutlineIndent {
|
||||||
|
@ -11,7 +11,7 @@ use typst_library::foundations::{Content, LinkMarker, Packed, StyleChain};
|
|||||||
use typst_library::introspection::Location;
|
use typst_library::introspection::Location;
|
||||||
use typst_library::layout::RepeatElem;
|
use typst_library::layout::RepeatElem;
|
||||||
use typst_library::model::{
|
use typst_library::model::{
|
||||||
Destination, FigureCaption, FigureElem, HeadingElem, Outlinable, OutlineElem,
|
Destination, FigureCaption, FigureElem, HeadingElem, Outlinable, OutlineBody,
|
||||||
OutlineEntry, TableCell, TableElem,
|
OutlineEntry, TableCell, TableElem,
|
||||||
};
|
};
|
||||||
use typst_library::pdf::{ArtifactElem, ArtifactKind, PdfTagElem, PdfTagKind};
|
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
|
// TODO: when targeting PDF 2.0 headings `> 6` are supported
|
||||||
_ => TagKind::H6(Some(name)).into(),
|
_ => 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()));
|
push_stack(gc, loc, StackEntryKind::Outline(OutlineCtx::new()));
|
||||||
return;
|
return;
|
||||||
} else if let Some(entry) = elem.to_packed::<OutlineEntry>() {
|
} else if let Some(entry) = elem.to_packed::<OutlineEntry>() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user