summaryrefslogtreecommitdiff
path: root/src/eval/template.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-02-24 18:47:43 +0100
committerLaurenz <laurmaedje@gmail.com>2022-02-24 19:15:11 +0100
commit49c0bac44dda8be643480df2c4e68623eeec91bd (patch)
tree6f697031013e4259bdfefc7977edc8d9d683e823 /src/eval/template.rs
parent90132b0d658f1b2a5df75eb458150e6782b2c30c (diff)
First-line indents
Co-Authored-By: Martin Haug <mhaug@live.de>
Diffstat (limited to 'src/eval/template.rs')
-rw-r--r--src/eval/template.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/eval/template.rs b/src/eval/template.rs
index a9e1262f..fb624600 100644
--- a/src/eval/template.rs
+++ b/src/eval/template.rs
@@ -445,8 +445,36 @@ impl<'a> Builder<'a> {
/// Finish the currently built paragraph.
fn finish_par(&mut self, styles: StyleChain<'a>) {
- let (par, shared) = std::mem::take(&mut self.par).finish();
+ let (mut par, shared) = std::mem::take(&mut self.par).finish();
if !par.is_empty() {
+ // Paragraph indent should only apply if the paragraph starts with
+ // text and follows directly after another paragraph.
+ let indent = shared.get(ParNode::INDENT);
+ if !indent.is_zero()
+ && par
+ .items()
+ .find_map(|child| match child {
+ ParChild::Spacing(_) => None,
+ ParChild::Text(_) => Some(true),
+ ParChild::Node(_) => Some(false),
+ })
+ .unwrap_or_default()
+ && self
+ .flow
+ .items()
+ .rev()
+ .find_map(|child| match child {
+ FlowChild::Leading => None,
+ FlowChild::Parbreak => None,
+ FlowChild::Node(node) => Some(node.is::<ParNode>()),
+ FlowChild::Spacing(_) => Some(false),
+ FlowChild::Colbreak => Some(false),
+ })
+ .unwrap_or_default()
+ {
+ par.push_front(ParChild::Spacing(SpacingKind::Linear(indent)))
+ }
+
let node = ParNode(par).pack();
self.flow.supportive(FlowChild::Node(node), shared);
}