mirror of
https://github.com/typst/typst
synced 2025-08-15 23:48:32 +08:00
wip: make it work (somewhat, see fixmes)
This commit is contained in:
parent
f4b02fa705
commit
cb779baa86
@ -227,8 +227,9 @@ impl Show for Packed<BibliographyElem> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Does this get the keys in the same order as the loop below with references?
|
// FIXME: This is always lexicographically ordered which violates "citation-order" styles!
|
||||||
let keys = BibliographyElem::keys(engine.introspector);
|
let keys = BibliographyElem::keys(engine.introspector);
|
||||||
|
|
||||||
let works = Works::generate(engine).at(span)?;
|
let works = Works::generate(engine).at(span)?;
|
||||||
let references = works
|
let references = works
|
||||||
.references
|
.references
|
||||||
@ -240,20 +241,21 @@ impl Show for Packed<BibliographyElem> {
|
|||||||
let row_gutter = ParElem::spacing_in(styles);
|
let row_gutter = ParElem::spacing_in(styles);
|
||||||
let mut cells = vec![];
|
let mut cells = vec![];
|
||||||
|
|
||||||
// FIXME: Not quite correct as `prefix` and `body` are now one grid cell instead of two (how to "split" content?)!
|
|
||||||
for (idx, (prefix, reference)) in references.iter().enumerate() {
|
for (idx, (prefix, reference)) in references.iter().enumerate() {
|
||||||
let indent =
|
|
||||||
if works.hanging_indent { Some(INDENT.into()) } else { None };
|
|
||||||
let entry = BibliographyEntry::new(keys[idx].0, reference.clone())
|
let entry = BibliographyEntry::new(keys[idx].0, reference.clone())
|
||||||
.with_prefix(prefix.clone())
|
.with_prefix(prefix.clone())
|
||||||
.with_indent(indent);
|
|
||||||
|
|
||||||
cells.push(
|
|
||||||
entry
|
|
||||||
.pack()
|
.pack()
|
||||||
.try_into()
|
.spanned(span);
|
||||||
.expect("todo: conversion content to GridChild"),
|
|
||||||
|
// FIXME: This does not work, unaffected by show-rules!
|
||||||
|
// (Just using `entry` as-is would work, however that would eliminate the grid)
|
||||||
|
let (e_prefix, body) = (
|
||||||
|
entry.field_by_name("prefix").unwrap(),
|
||||||
|
entry.field_by_name("body").unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
cells.push(e_prefix.display().try_into().expect("aaah"));
|
||||||
|
cells.push(body.display().try_into().expect("aaah"));
|
||||||
}
|
}
|
||||||
|
|
||||||
seq.push(
|
seq.push(
|
||||||
@ -266,7 +268,10 @@ impl Show for Packed<BibliographyElem> {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
for (idx, (_, reference)) in references.iter().enumerate() {
|
for (idx, (_, reference)) in references.iter().enumerate() {
|
||||||
let entry = BibliographyEntry::new(keys[idx].0, reference.clone());
|
let entry =
|
||||||
|
BibliographyEntry::new(keys[idx].0, reference.clone()).with_indent(
|
||||||
|
if works.hanging_indent { Some(INDENT.into()) } else { None },
|
||||||
|
);
|
||||||
seq.push(entry.pack().spanned(span));
|
seq.push(entry.pack().spanned(span));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -381,18 +386,16 @@ 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, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
|
fn show(&self, _: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
|
||||||
if self.prefix.is_some() {
|
if self.prefix(styles).is_some() {
|
||||||
let prefix = GridChild::Item(GridItem::Cell(
|
let prefix = GridChild::Item(GridItem::Cell(
|
||||||
Packed::new(GridCell::new(self.prefix(styles).unwrap()))
|
Packed::new(GridCell::new(self.prefix(styles).unwrap()))
|
||||||
.spanned(self.span()),
|
.spanned(self.span()),
|
||||||
))
|
));
|
||||||
.into_value();
|
|
||||||
let body = GridChild::Item(GridItem::Cell(
|
let body = GridChild::Item(GridItem::Cell(
|
||||||
Packed::new(GridCell::new(self.body.clone())).spanned(self.span()),
|
Packed::new(GridCell::new(self.body.clone())).spanned(self.span()),
|
||||||
))
|
));
|
||||||
.into_value();
|
|
||||||
|
|
||||||
return Ok(Content::sequence([prefix.display(), body.display()]));
|
Ok(GridElem::new(vec![prefix, body]).pack().spanned(self.span()))
|
||||||
} else {
|
} else {
|
||||||
let block = if let Some(indent) = self.indent(styles) {
|
let block = if let Some(indent) = self.indent(styles) {
|
||||||
let body = HElem::new(Spacing::Rel(-indent)).pack() + self.body.clone();
|
let body = HElem::new(Spacing::Rel(-indent)).pack() + self.body.clone();
|
||||||
@ -406,7 +409,7 @@ impl Show for Packed<BibliographyEntry> {
|
|||||||
BlockElem::new().with_body(Some(BlockBody::Content(self.body.clone())))
|
BlockElem::new().with_body(Some(BlockBody::Content(self.body.clone())))
|
||||||
};
|
};
|
||||||
|
|
||||||
return Ok(block.pack().spanned(self.span()));
|
Ok(block.pack().spanned(self.span()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user