Keep verse line breaks as separate lines
This commit is contained in:
1 parent
1b147235b0
commit
df977704c5
4 files changed
+40
-4
No files matched your search
@@ -3350,6 +3350,28 @@ fn standalone_graphic(raw: &str) -> Option<SourceParagraph> {
|
||||
})
|
||||
}
|
||||
|
||||
fn verse_block(raw: &str) -> Option<Vec<SourceParagraph>> {
|
||||
let body = raw
|
||||
.trim()
|
||||
.strip_prefix("\\begin{verse}")?
|
||||
.strip_suffix("\\end{verse}")?;
|
||||
let mut blocks = Vec::new();
|
||||
for line in body.split("\\\\") {
|
||||
let text = line.trim();
|
||||
if text.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let mut block = parse_paragraph(text);
|
||||
block.left_skip = 20;
|
||||
blocks.push(block);
|
||||
}
|
||||
if blocks.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(blocks)
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_blocks_raw(
|
||||
raw: &str,
|
||||
definitions: &[TheoremDefinition],
|
||||
@@ -3458,6 +3480,9 @@ fn parse_blocks_raw(
|
||||
if let Some(blocks) = list_blocks(raw, 0, definitions, spacing) {
|
||||
return blocks;
|
||||
}
|
||||
if let Some(blocks) = verse_block(raw) {
|
||||
return blocks;
|
||||
}
|
||||
if let Some(body) = raw
|
||||
.strip_prefix("\\begin{quotation}")
|
||||
.and_then(|text| text.strip_suffix("\\end{quotation}"))
|
||||
@@ -6862,6 +6887,17 @@ See \ref{fig:a} and \ref{tab:b}.";
|
||||
assert_eq!(blocks[1].space_before, 5, "12pt itemsep");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verse_keeps_its_line_breaks() {
|
||||
let blocks =
|
||||
paragraphs("\\begin{verse}\nline one \\\\\nline two\n\\end{verse}").expect("verse");
|
||||
assert_eq!(blocks.len(), 2);
|
||||
assert_eq!(blocks[0].text, "line one");
|
||||
assert_eq!(blocks[0].left_skip, 20);
|
||||
assert_eq!(blocks[1].text, "line two");
|
||||
assert_eq!(blocks[1].left_skip, 20);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn quotation_indents_both_margins() {
|
||||
let source = "\\begin{quotation}\nOne paragraph.\n\nTwo paragraph.\n\\end{quotation}";
|
||||
|
||||
Reference in new issue
Block a user