Keep raggedright blocks unjustified

This commit is contained in:
gloamxun committed 2026-10-26 04:44:21 +08:00
1 parent 337f1f6de6
commit f11561f15f
3 files changed
+17 -3

No files matched your search

+15 -1
View File
@@ -9294,6 +9294,11 @@ fn build_document_with_labels(
text = strip_noop_commands(&text);
let mut centered = paragraph.centered;
let mut right_aligned = paragraph.right_aligned;
let mut ragged = false;
if let Some(rest) = text.trim_start().strip_prefix("\\raggedright") {
ragged = true;
text = rest.trim_start().to_string();
}
let trimmed = text.trim_start();
if let Some(rest) = trimmed.strip_prefix("\\centering") {
centered = true;
@@ -9346,7 +9351,7 @@ fn build_document_with_labels(
centered,
right_aligned,
looseness: geometry.looseness.unwrap_or(0),
ragged_right: false,
ragged_right: ragged,
right_skip: geometry.right_skip.unwrap_or(0) + paragraph.right_skip * SCALE,
hang_indent: geometry.hang_indent.unwrap_or(0),
hang_after: geometry.hang_after.unwrap_or(1) as i32,
@@ -13391,6 +13396,15 @@ A definition.
assert_eq!(blocks[0].text, "See In body.");
}
#[test]
fn raggedright_declaration_keeps_lines_short() {
let blocks = paragraphs("\\raggedright A line of text.").expect("paragraphs");
let document = build_document(&blocks, &PageGeometry::default());
let style = document.units[0].paragraph_style.clone().expect("style");
assert!(style.ragged_right);
assert_eq!(document.units[0].source, "A line of text.");
}
#[test]
fn centering_declaration_centres_the_block() {
let blocks = paragraphs("\\centering Short.").expect("paragraphs");