mirror of
https://github.com/typst/typst
synced 2025-06-28 16:22:53 +08:00
Fix linebreak after inline objects with metadata
This commit is contained in:
parent
9025ecb2ee
commit
46ce9c94e3
@ -318,7 +318,8 @@ impl Segment<'_> {
|
|||||||
Self::Text(len) => len,
|
Self::Text(len) => len,
|
||||||
Self::Spacing(_) => SPACING_REPLACE.len_utf8(),
|
Self::Spacing(_) => SPACING_REPLACE.len_utf8(),
|
||||||
Self::Box(_, true) => SPACING_REPLACE.len_utf8(),
|
Self::Box(_, true) => SPACING_REPLACE.len_utf8(),
|
||||||
Self::Equation(_) | Self::Box(_, _) | Self::Meta => OBJ_REPLACE.len_utf8(),
|
Self::Equation(_) | Self::Box(_, _) => OBJ_REPLACE.len_utf8(),
|
||||||
|
Self::Meta => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -334,6 +335,8 @@ enum Item<'a> {
|
|||||||
Fractional(Fr, Option<(&'a BoxElem, StyleChain<'a>)>),
|
Fractional(Fr, Option<(&'a BoxElem, StyleChain<'a>)>),
|
||||||
/// Layouted inline-level content.
|
/// Layouted inline-level content.
|
||||||
Frame(Frame),
|
Frame(Frame),
|
||||||
|
/// Metadata.
|
||||||
|
Meta(Frame),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Item<'a> {
|
impl<'a> Item<'a> {
|
||||||
@ -351,6 +354,7 @@ impl<'a> Item<'a> {
|
|||||||
Self::Text(shaped) => shaped.text.len(),
|
Self::Text(shaped) => shaped.text.len(),
|
||||||
Self::Absolute(_) | Self::Fractional(_, _) => SPACING_REPLACE.len_utf8(),
|
Self::Absolute(_) | Self::Fractional(_, _) => SPACING_REPLACE.len_utf8(),
|
||||||
Self::Frame(_) => OBJ_REPLACE.len_utf8(),
|
Self::Frame(_) => OBJ_REPLACE.len_utf8(),
|
||||||
|
Self::Meta(_) => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,7 +364,7 @@ impl<'a> Item<'a> {
|
|||||||
Self::Text(shaped) => shaped.width,
|
Self::Text(shaped) => shaped.width,
|
||||||
Self::Absolute(v) => *v,
|
Self::Absolute(v) => *v,
|
||||||
Self::Frame(frame) => frame.width(),
|
Self::Frame(frame) => frame.width(),
|
||||||
Self::Fractional(_, _) => Abs::zero(),
|
Self::Fractional(_, _) | Self::Meta(_) => Abs::zero(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -585,7 +589,6 @@ fn collect<'a>(
|
|||||||
full.push(if frac { SPACING_REPLACE } else { OBJ_REPLACE });
|
full.push(if frac { SPACING_REPLACE } else { OBJ_REPLACE });
|
||||||
Segment::Box(elem, frac)
|
Segment::Box(elem, frac)
|
||||||
} else if child.is::<MetaElem>() {
|
} else if child.is::<MetaElem>() {
|
||||||
full.push(OBJ_REPLACE);
|
|
||||||
Segment::Meta
|
Segment::Meta
|
||||||
} else {
|
} else {
|
||||||
bail!(child.span(), "unexpected paragraph child");
|
bail!(child.span(), "unexpected paragraph child");
|
||||||
@ -670,7 +673,7 @@ fn prepare<'a>(
|
|||||||
Segment::Meta => {
|
Segment::Meta => {
|
||||||
let mut frame = Frame::new(Size::zero());
|
let mut frame = Frame::new(Size::zero());
|
||||||
frame.meta(styles, true);
|
frame.meta(styles, true);
|
||||||
items.push(Item::Frame(frame));
|
items.push(Item::Meta(frame));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1336,7 +1339,7 @@ fn commit(
|
|||||||
let frame = shaped.build(vt, justification_ratio, extra_justification);
|
let frame = shaped.build(vt, justification_ratio, extra_justification);
|
||||||
push(&mut offset, frame);
|
push(&mut offset, frame);
|
||||||
}
|
}
|
||||||
Item::Frame(frame) => {
|
Item::Frame(frame) | Item::Meta(frame) => {
|
||||||
push(&mut offset, frame.clone());
|
push(&mut offset, frame.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
tests/ref/meta/query-figure.png
Normal file
BIN
tests/ref/meta/query-figure.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 282 KiB |
BIN
tests/ref/meta/query-header.png
Normal file
BIN
tests/ref/meta/query-header.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 118 KiB |
Binary file not shown.
Before Width: | Height: | Size: 542 KiB |
BIN
tests/ref/text/linebreak-obj.png
Normal file
BIN
tests/ref/text/linebreak-obj.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
@ -1,35 +1,4 @@
|
|||||||
// Test the query function.
|
// Test a list of figures.
|
||||||
|
|
||||||
---
|
|
||||||
#set page(
|
|
||||||
paper: "a7",
|
|
||||||
margin: (y: 1cm, x: 0.5cm),
|
|
||||||
header: {
|
|
||||||
smallcaps[Typst Academy]
|
|
||||||
h(1fr)
|
|
||||||
locate(it => {
|
|
||||||
let after = query(selector(heading).after(it), it)
|
|
||||||
let before = query(selector(heading).before(it), it)
|
|
||||||
let elem = if before.len() != 0 {
|
|
||||||
before.last()
|
|
||||||
} else if after.len() != 0 {
|
|
||||||
after.first()
|
|
||||||
}
|
|
||||||
emph(elem.body)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
#outline()
|
|
||||||
|
|
||||||
= Introduction
|
|
||||||
#lorem(35)
|
|
||||||
|
|
||||||
= Background
|
|
||||||
#lorem(35)
|
|
||||||
|
|
||||||
= Approach
|
|
||||||
#lorem(60)
|
|
||||||
|
|
||||||
---
|
---
|
||||||
#set page(
|
#set page(
|
32
tests/typ/meta/query-header.typ
Normal file
32
tests/typ/meta/query-header.typ
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Test creating a header with the query function.
|
||||||
|
|
||||||
|
---
|
||||||
|
#set page(
|
||||||
|
paper: "a7",
|
||||||
|
margin: (y: 1cm, x: 0.5cm),
|
||||||
|
header: {
|
||||||
|
smallcaps[Typst Academy]
|
||||||
|
h(1fr)
|
||||||
|
locate(it => {
|
||||||
|
let after = query(selector(heading).after(it), it)
|
||||||
|
let before = query(selector(heading).before(it), it)
|
||||||
|
let elem = if before.len() != 0 {
|
||||||
|
before.last()
|
||||||
|
} else if after.len() != 0 {
|
||||||
|
after.first()
|
||||||
|
}
|
||||||
|
emph(elem.body)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
#outline()
|
||||||
|
|
||||||
|
= Introduction
|
||||||
|
#lorem(35)
|
||||||
|
|
||||||
|
= Background
|
||||||
|
#lorem(35)
|
||||||
|
|
||||||
|
= Approach
|
||||||
|
#lorem(60)
|
18
tests/typ/text/linebreak-obj.typ
Normal file
18
tests/typ/text/linebreak-obj.typ
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Test linebreaks with after inline elements.
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test punctuation after citations.
|
||||||
|
#set page(width: 162pt)
|
||||||
|
|
||||||
|
They can look for the details in @netwok,
|
||||||
|
which is the authorative source.
|
||||||
|
|
||||||
|
#bibliography("/works.bib")
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test punctuation after math equations.
|
||||||
|
#set page(width: 85pt)
|
||||||
|
|
||||||
|
We prove $1 < 2$. \
|
||||||
|
We prove $1 < 2$! \
|
||||||
|
We prove $1 < 2$– \
|
Loading…
x
Reference in New Issue
Block a user