Support show-set for outline and bibliography headings

This commit is contained in:
Laurenz 2023-04-23 15:01:34 +02:00
parent e9a0cf9741
commit ff1e4049d1
4 changed files with 31 additions and 15 deletions

View File

@ -43,7 +43,7 @@ use crate::text::TextElem;
///
/// Display: Bibliography
/// Category: meta
#[element(Locatable, Synthesize, Show, LocalName)]
#[element(Locatable, Synthesize, Show, Finalize, LocalName)]
pub struct BibliographyElem {
/// Path to a Hayagriva `.yml` or BibLaTeX `.bib` file.
#[required]
@ -66,6 +66,11 @@ pub struct BibliographyElem {
/// language]($func/text.lang) will be used. This is the default.
/// - When set to `{none}`, the bibliography will not have a title.
/// - A custom title can be set by passing content.
///
/// The bibliography's heading will not be numbered by default, but you can
/// force it to be with a show-set rule:
/// `{show bibliography: set heading(numbering: "1.")}`
/// ```
#[default(Some(Smart::Auto))]
pub title: Option<Smart<Content>>,
@ -152,12 +157,7 @@ impl Show for BibliographyElem {
.spanned(self.span())
});
seq.push(
HeadingElem::new(title)
.with_level(NonZeroUsize::ONE)
.with_numbering(None)
.pack(),
);
seq.push(HeadingElem::new(title).with_level(NonZeroUsize::ONE).pack());
}
if !vt.introspector.init() {
@ -199,6 +199,12 @@ impl Show for BibliographyElem {
}
}
impl Finalize for BibliographyElem {
fn finalize(&self, realized: Content, _: StyleChain) -> Content {
realized.styled(HeadingElem::set_numbering(None))
}
}
impl LocalName for BibliographyElem {
fn local_name(&self, lang: Lang) -> &'static str {
match lang {

View File

@ -47,7 +47,7 @@ use crate::text::{LinebreakElem, SpaceElem, TextElem};
///
/// Display: Outline
/// Category: meta
#[element(Show, LocalName)]
#[element(Show, Finalize, LocalName)]
pub struct OutlineElem {
/// The title of the outline.
///
@ -55,6 +55,11 @@ pub struct OutlineElem {
/// [text language]($func/text.lang) will be used. This is the default.
/// - When set to `{none}`, the outline will not have a title.
/// - A custom title can be set by passing content.
///
/// The outline's heading will not be numbered by default, but you can
/// force it to be with a show-set rule:
/// `{show outline: set heading(numbering: "1.")}`
/// ```
#[default(Some(Smart::Auto))]
pub title: Option<Smart<Content>>,
@ -141,13 +146,7 @@ impl Show for OutlineElem {
.spanned(self.span())
});
seq.push(
HeadingElem::new(title)
.with_level(NonZeroUsize::ONE)
.with_numbering(None)
.with_outlined(false)
.pack(),
);
seq.push(HeadingElem::new(title).with_level(NonZeroUsize::ONE).pack());
}
let indent = self.indent(styles);
@ -247,6 +246,14 @@ impl Show for OutlineElem {
}
}
impl Finalize for OutlineElem {
fn finalize(&self, realized: Content, _: StyleChain) -> Content {
realized
.styled(HeadingElem::set_outlined(false))
.styled(HeadingElem::set_numbering(None))
}
}
impl LocalName for OutlineElem {
fn local_name(&self, lang: Lang) -> &'static str {
match lang {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 163 KiB

After

Width:  |  Height:  |  Size: 115 KiB

View File

@ -30,6 +30,9 @@ And quark! @quark
---
#set page(width: 200pt)
#set heading(numbering: "1.")
#show bibliography: set heading(numbering: "1.")
= Multiple Bibs
Now we have multiple bibliographies containing #cite("glacier-melt", "keshav2007read")
#bibliography(("/works.bib", "/works_too.bib"))