mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Support show-set for outline and bibliography headings
This commit is contained in:
parent
e9a0cf9741
commit
ff1e4049d1
@ -43,7 +43,7 @@ use crate::text::TextElem;
|
|||||||
///
|
///
|
||||||
/// Display: Bibliography
|
/// Display: Bibliography
|
||||||
/// Category: meta
|
/// Category: meta
|
||||||
#[element(Locatable, Synthesize, Show, LocalName)]
|
#[element(Locatable, Synthesize, Show, Finalize, LocalName)]
|
||||||
pub struct BibliographyElem {
|
pub struct BibliographyElem {
|
||||||
/// Path to a Hayagriva `.yml` or BibLaTeX `.bib` file.
|
/// Path to a Hayagriva `.yml` or BibLaTeX `.bib` file.
|
||||||
#[required]
|
#[required]
|
||||||
@ -66,6 +66,11 @@ pub struct BibliographyElem {
|
|||||||
/// language]($func/text.lang) will be used. This is the default.
|
/// language]($func/text.lang) will be used. This is the default.
|
||||||
/// - When set to `{none}`, the bibliography will not have a title.
|
/// - When set to `{none}`, the bibliography will not have a title.
|
||||||
/// - A custom title can be set by passing content.
|
/// - 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))]
|
#[default(Some(Smart::Auto))]
|
||||||
pub title: Option<Smart<Content>>,
|
pub title: Option<Smart<Content>>,
|
||||||
|
|
||||||
@ -152,12 +157,7 @@ impl Show for BibliographyElem {
|
|||||||
.spanned(self.span())
|
.spanned(self.span())
|
||||||
});
|
});
|
||||||
|
|
||||||
seq.push(
|
seq.push(HeadingElem::new(title).with_level(NonZeroUsize::ONE).pack());
|
||||||
HeadingElem::new(title)
|
|
||||||
.with_level(NonZeroUsize::ONE)
|
|
||||||
.with_numbering(None)
|
|
||||||
.pack(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !vt.introspector.init() {
|
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 {
|
impl LocalName for BibliographyElem {
|
||||||
fn local_name(&self, lang: Lang) -> &'static str {
|
fn local_name(&self, lang: Lang) -> &'static str {
|
||||||
match lang {
|
match lang {
|
||||||
|
@ -47,7 +47,7 @@ use crate::text::{LinebreakElem, SpaceElem, TextElem};
|
|||||||
///
|
///
|
||||||
/// Display: Outline
|
/// Display: Outline
|
||||||
/// Category: meta
|
/// Category: meta
|
||||||
#[element(Show, LocalName)]
|
#[element(Show, Finalize, LocalName)]
|
||||||
pub struct OutlineElem {
|
pub struct OutlineElem {
|
||||||
/// The title of the outline.
|
/// The title of the outline.
|
||||||
///
|
///
|
||||||
@ -55,6 +55,11 @@ pub struct OutlineElem {
|
|||||||
/// [text language]($func/text.lang) will be used. This is the default.
|
/// [text language]($func/text.lang) will be used. This is the default.
|
||||||
/// - When set to `{none}`, the outline will not have a title.
|
/// - When set to `{none}`, the outline will not have a title.
|
||||||
/// - A custom title can be set by passing content.
|
/// - 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))]
|
#[default(Some(Smart::Auto))]
|
||||||
pub title: Option<Smart<Content>>,
|
pub title: Option<Smart<Content>>,
|
||||||
|
|
||||||
@ -141,13 +146,7 @@ impl Show for OutlineElem {
|
|||||||
.spanned(self.span())
|
.spanned(self.span())
|
||||||
});
|
});
|
||||||
|
|
||||||
seq.push(
|
seq.push(HeadingElem::new(title).with_level(NonZeroUsize::ONE).pack());
|
||||||
HeadingElem::new(title)
|
|
||||||
.with_level(NonZeroUsize::ONE)
|
|
||||||
.with_numbering(None)
|
|
||||||
.with_outlined(false)
|
|
||||||
.pack(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let indent = self.indent(styles);
|
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 {
|
impl LocalName for OutlineElem {
|
||||||
fn local_name(&self, lang: Lang) -> &'static str {
|
fn local_name(&self, lang: Lang) -> &'static str {
|
||||||
match lang {
|
match lang {
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 163 KiB After Width: | Height: | Size: 115 KiB |
@ -30,6 +30,9 @@ And quark! @quark
|
|||||||
|
|
||||||
---
|
---
|
||||||
#set page(width: 200pt)
|
#set page(width: 200pt)
|
||||||
|
#set heading(numbering: "1.")
|
||||||
|
#show bibliography: set heading(numbering: "1.")
|
||||||
|
|
||||||
= Multiple Bibs
|
= Multiple Bibs
|
||||||
Now we have multiple bibliographies containing #cite("glacier-melt", "keshav2007read")
|
Now we have multiple bibliographies containing #cite("glacier-melt", "keshav2007read")
|
||||||
#bibliography(("/works.bib", "/works_too.bib"))
|
#bibliography(("/works.bib", "/works_too.bib"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user