Fix first line indent with styled text

This commit is contained in:
Laurenz 2023-04-05 00:15:05 +02:00
parent 715f9fb0a5
commit e13c72b301
3 changed files with 17 additions and 30 deletions

View File

@ -83,15 +83,16 @@ pub struct ParElem {
#[default]
pub linebreaks: Smart<Linebreaks>,
/// The indent the first line of a consecutive paragraph should have.
/// The indent the first line of a paragraph should have.
///
/// The first paragraph on a page will never be indented.
/// Only the first line of a consecutive paragraph will be intended (not
/// the first one in a block or on the page).
///
/// By typographic convention, paragraph breaks are indicated by either some
/// space between paragraphs or indented first lines. Consider turning the
/// [paragraph spacing]($func/block.spacing) off when using this property
/// (e.g. using `[#show par: set block(spacing: 0pt)]`).
#[resolve]
/// By typographic convention, paragraph breaks are indicated either by some
/// space between paragraphs or by indented first lines. Consider reducing
/// the [paragraph spacing]($func/block.spacing) to the [`leading`] when
/// using this property (e.g. using
/// `[#show par: set block(spacing: 0.65em)]`).
pub first_line_indent: Length,
/// The indent all but the first line of a paragraph should have.
@ -498,27 +499,14 @@ fn collect<'a>(
let mut spans = SpanMapper::new();
let mut iter = children.iter().peekable();
if consecutive {
let first_line_indent = ParElem::first_line_indent_in(*styles);
if !first_line_indent.is_zero()
&& children
.iter()
.find_map(|child| {
if child.with::<dyn Behave>().map_or(false, |behaved| {
behaved.behaviour() == Behaviour::Ignorant
}) {
None
} else if child.is::<TextElem>() || child.is::<SmartQuoteElem>() {
Some(true)
} else {
Some(false)
}
})
.unwrap_or_default()
{
full.push(SPACING_REPLACE);
segments.push((Segment::Spacing(first_line_indent.into()), *styles));
}
let first_line_indent = ParElem::first_line_indent_in(*styles);
if !first_line_indent.is_zero()
&& consecutive
&& AlignElem::alignment_in(*styles).x.resolve(*styles)
== TextElem::dir_in(*styles).start().into()
{
full.push(SPACING_REPLACE);
segments.push((Segment::Spacing(first_line_indent.into()), *styles));
}
let hang = ParElem::hanging_indent_in(*styles);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB

View File

@ -10,7 +10,7 @@ The first paragraph has no indent.
But the second one does.
#box(image("/tiger.jpg", height: 6pt))
starts a paragraph without indent.
starts a paragraph, also with indent.
#align(center, image("/rhino.png", width: 1cm))
@ -28,7 +28,6 @@ starts a paragraph without indent.
ثم يصبح النص رطبًا وقابل للطرق ويبدو المستند رائعًا.
---
// This is madness.
#set par(first-line-indent: 12pt)