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] #[default]
pub linebreaks: Smart<Linebreaks>, 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 /// By typographic convention, paragraph breaks are indicated either by some
/// space between paragraphs or indented first lines. Consider turning the /// space between paragraphs or by indented first lines. Consider reducing
/// [paragraph spacing]($func/block.spacing) off when using this property /// the [paragraph spacing]($func/block.spacing) to the [`leading`] when
/// (e.g. using `[#show par: set block(spacing: 0pt)]`). /// using this property (e.g. using
#[resolve] /// `[#show par: set block(spacing: 0.65em)]`).
pub first_line_indent: Length, pub first_line_indent: Length,
/// The indent all but the first line of a paragraph should have. /// 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 spans = SpanMapper::new();
let mut iter = children.iter().peekable(); let mut iter = children.iter().peekable();
if consecutive { let first_line_indent = ParElem::first_line_indent_in(*styles);
let first_line_indent = ParElem::first_line_indent_in(*styles); if !first_line_indent.is_zero()
if !first_line_indent.is_zero() && consecutive
&& children && AlignElem::alignment_in(*styles).x.resolve(*styles)
.iter() == TextElem::dir_in(*styles).start().into()
.find_map(|child| { {
if child.with::<dyn Behave>().map_or(false, |behaved| { full.push(SPACING_REPLACE);
behaved.behaviour() == Behaviour::Ignorant segments.push((Segment::Spacing(first_line_indent.into()), *styles));
}) {
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 hang = ParElem::hanging_indent_in(*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. But the second one does.
#box(image("/tiger.jpg", height: 6pt)) #box(image("/tiger.jpg", height: 6pt))
starts a paragraph without indent. starts a paragraph, also with indent.
#align(center, image("/rhino.png", width: 1cm)) #align(center, image("/rhino.png", width: 1cm))
@ -28,7 +28,6 @@ starts a paragraph without indent.
ثم يصبح النص رطبًا وقابل للطرق ويبدو المستند رائعًا. ثم يصبح النص رطبًا وقابل للطرق ويبدو المستند رائعًا.
--- ---
// This is madness. // This is madness.
#set par(first-line-indent: 12pt) #set par(first-line-indent: 12pt)