mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 18:04:48 +00:00
craft-latex: a starred line break shows no star
`\\*` is a line break that also forbids a page break after it. The lexer read `\\` as the control symbol and left the `*` as text, so `a\\*b` showed `a`, a line break, then `*b`, `\\*[3pt]` showed `*[3pt]`, and in a tabular the next row's first cell started with `*`. The lexer now takes the star with `\\`, so the parser and the tabular reader see the line break they already handle, with its optional spacing argument.
This commit is contained in:
@@ -136,6 +136,14 @@ impl Lexer<'_> {
|
||||
let m = self.until("\\]");
|
||||
self.out.push(Tok::Math(m, true));
|
||||
}
|
||||
'\\' => {
|
||||
// `\\*` breaks the line as `\\` does; the star only forbids a page
|
||||
// break there.
|
||||
if self.peek() == Some('*') {
|
||||
self.bump();
|
||||
}
|
||||
self.out.push(Tok::Cmd(sym.to_string()));
|
||||
}
|
||||
_ => self.out.push(Tok::Cmd(sym.to_string())),
|
||||
}
|
||||
continue;
|
||||
|
||||
@@ -437,3 +437,17 @@ fn a_tabular_row_keeps_the_cells_a_table_row_holds() {
|
||||
assert_eq!(t.rows.first().map(Vec::len), Some(craft_wordmodel::table::MAX_COLS));
|
||||
assert_eq!(t.rows.get(1).map(Vec::len), Some(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_starred_line_break_shows_no_star() {
|
||||
// `\\*` (a line break with no page break after it) left its `*` in the text.
|
||||
for src in ["a\\\\*b", "a\\\\*[3pt]b", "a\\\\b"] {
|
||||
let p = paras(&format!("\\begin{{document}}{src}\\end{{document}}"));
|
||||
assert_eq!(p.len(), 1, "{src}");
|
||||
assert_eq!(p[0].text().replace(['\n', '\u{B}'], "|"), "a|b", "{src}");
|
||||
}
|
||||
let flow = parse("\\begin{document}\\begin{tabular}{ll}a & b \\\\* c & d\\end{tabular}\\end{document}");
|
||||
let Some(FBlock::Table(t)) = flow.blocks.first() else { panic!("{:?}", flow.blocks) };
|
||||
assert_eq!(t.rows.len(), 2, "{t:?}");
|
||||
assert_eq!(t.rows[1].iter().map(|c| c.text().trim().to_string()).collect::<Vec<_>>(), ["c", "d"]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user