mirror of
https://github.com/typst/typst
synced 2025-08-16 16:08:32 +08:00
chore: abandon grid elem for bib entry
This commit is contained in:
parent
b57300d37d
commit
618a94cd2b
@ -34,8 +34,7 @@ use crate::layout::{
|
|||||||
};
|
};
|
||||||
use crate::loading::{DataSource, Load};
|
use crate::loading::{DataSource, Load};
|
||||||
use crate::model::{
|
use crate::model::{
|
||||||
CitationForm, CiteGroup, Destination, FootnoteElem, HeadingElem, LinkElem, ParElem,
|
CitationForm, CiteGroup, Destination, FootnoteElem, HeadingElem, LinkElem, Url,
|
||||||
Url,
|
|
||||||
};
|
};
|
||||||
use crate::routines::{EvalMode, Routines};
|
use crate::routines::{EvalMode, Routines};
|
||||||
use crate::text::{
|
use crate::text::{
|
||||||
@ -210,12 +209,11 @@ impl Synthesize for Packed<BibliographyElem> {
|
|||||||
impl Show for Packed<BibliographyElem> {
|
impl Show for Packed<BibliographyElem> {
|
||||||
#[typst_macros::time(name = "bibliography", span = self.span())]
|
#[typst_macros::time(name = "bibliography", span = self.span())]
|
||||||
fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
|
fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
|
||||||
const _COLUMN_GUTTER: Em = Em::new(0.65);
|
|
||||||
const INDENT: Em = Em::new(1.5);
|
const INDENT: Em = Em::new(1.5);
|
||||||
|
|
||||||
let span = self.span();
|
let span = self.span();
|
||||||
|
|
||||||
let mut seq = vec![];
|
let mut seq = vec![];
|
||||||
|
|
||||||
if let Some(title) = self.title(styles).unwrap_or_else(|| {
|
if let Some(title) = self.title(styles).unwrap_or_else(|| {
|
||||||
Some(TextElem::packed(Self::local_name_in(styles)).spanned(span))
|
Some(TextElem::packed(Self::local_name_in(styles)).spanned(span))
|
||||||
}) {
|
}) {
|
||||||
@ -234,40 +232,16 @@ impl Show for Packed<BibliographyElem> {
|
|||||||
.ok_or("CSL style is not suitable for bibliographies")
|
.ok_or("CSL style is not suitable for bibliographies")
|
||||||
.at(span)?;
|
.at(span)?;
|
||||||
|
|
||||||
if references.iter().any(|(_, prefix, _)| prefix.is_some()) {
|
|
||||||
let row_gutter = ParElem::spacing_in(styles);
|
|
||||||
let mut cells = vec![];
|
|
||||||
|
|
||||||
for (key, prefix, reference) in references {
|
for (key, prefix, reference) in references {
|
||||||
let label = Label::new(PicoStr::intern(key));
|
let label = Label::new(PicoStr::intern(key));
|
||||||
|
let indent = if works.hanging_indent { Some(INDENT.into()) } else { None };
|
||||||
let entry = BibliographyEntry::new(label, reference.clone())
|
let entry = BibliographyEntry::new(label, reference.clone())
|
||||||
.with_prefix(prefix.clone())
|
.with_prefix(prefix.clone())
|
||||||
|
.with_indent(indent)
|
||||||
.pack()
|
.pack()
|
||||||
.spanned(span);
|
.spanned(span);
|
||||||
|
|
||||||
cells.push(
|
seq.push(entry);
|
||||||
entry
|
|
||||||
.try_into()
|
|
||||||
.expect("conversion from Content to GridChild should not fail"),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
seq.push(
|
|
||||||
GridElem::new(cells)
|
|
||||||
.with_columns(TrackSizings(smallvec![Sizing::Auto; 1]))
|
|
||||||
// .with_column_gutter(TrackSizings(smallvec![COLUMN_GUTTER.into()]))
|
|
||||||
.with_row_gutter(TrackSizings(smallvec![row_gutter.into()]))
|
|
||||||
.pack()
|
|
||||||
.spanned(span),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
for (key, _, reference) in references {
|
|
||||||
let label = Label::new(PicoStr::intern(key));
|
|
||||||
let entry = BibliographyEntry::new(label, reference.clone()).with_indent(
|
|
||||||
if works.hanging_indent { Some(INDENT.into()) } else { None },
|
|
||||||
);
|
|
||||||
seq.push(entry.pack().spanned(span));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Content::sequence(seq))
|
Ok(Content::sequence(seq))
|
||||||
@ -389,7 +363,9 @@ impl BibliographyEntry {}
|
|||||||
impl Show for Packed<BibliographyEntry> {
|
impl Show for Packed<BibliographyEntry> {
|
||||||
#[typst_macros::time(name = "bibliography.entry", span = self.span())]
|
#[typst_macros::time(name = "bibliography.entry", span = self.span())]
|
||||||
fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
|
fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
|
||||||
|
const COLUMN_GUTTER: Em = Em::new(0.65);
|
||||||
let span = self.span();
|
let span = self.span();
|
||||||
|
|
||||||
if self.prefix(styles).is_some() {
|
if self.prefix(styles).is_some() {
|
||||||
let prefix = self.prefix(styles).unwrap();
|
let prefix = self.prefix(styles).unwrap();
|
||||||
let body = self.body.clone();
|
let body = self.body.clone();
|
||||||
@ -412,7 +388,7 @@ impl Show for Packed<BibliographyEntry> {
|
|||||||
frame.width()
|
frame.width()
|
||||||
};
|
};
|
||||||
let hanging_indent =
|
let hanging_indent =
|
||||||
prefix_width + Em::new(0.65).at(TextElem::size_in(styles));
|
prefix_width + COLUMN_GUTTER.at(TextElem::size_in(styles));
|
||||||
let inset = Sides::default()
|
let inset = Sides::default()
|
||||||
.with(TextElem::dir_in(styles).start(), Some(Rel::from(hanging_indent)));
|
.with(TextElem::dir_in(styles).start(), Some(Rel::from(hanging_indent)));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user