Capture longtable sources through the tabular path
This commit is contained in:
1 parent
d2497dd079
commit
25eef7097b
5 files changed
+55
-11
No files matched your search
+26
-7
@@ -1021,12 +1021,12 @@ fn geometry_counter(geometry: &PageGeometry, name: &str) -> u32 {
|
||||
fn strip_page_geometry(source: &str) -> (String, PageGeometry) {
|
||||
let mut geometry = PageGeometry::default();
|
||||
let mut body = String::new();
|
||||
let mut tabular: Option<(String, String)> = None;
|
||||
let mut tabular: Option<(String, String, &'static str)> = None;
|
||||
for line in source.lines() {
|
||||
let trimmed = line.trim();
|
||||
if let Some((_, text)) = tabular.as_mut() {
|
||||
if trimmed == "\\end{tabular}" {
|
||||
let (template, text) = tabular.take().unwrap();
|
||||
if let Some((_, text, environment)) = tabular.as_mut() {
|
||||
if trimmed == format!("\\end{{{environment}}}") {
|
||||
let (template, text, _) = tabular.take().unwrap();
|
||||
geometry.tabular.push((template, text));
|
||||
} else {
|
||||
if !text.is_empty() {
|
||||
@@ -1036,13 +1036,21 @@ fn strip_page_geometry(source: &str) -> (String, PageGeometry) {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if let Some(rest) = trimmed.strip_prefix("\\begin{tabular}") {
|
||||
let mut table_environment = None;
|
||||
for environment in ["tabular", "longtable"] {
|
||||
let begin = format!("\\begin{{{environment}}}");
|
||||
if let Some(rest) = trimmed.strip_prefix(&begin) {
|
||||
table_environment = Some((environment, rest));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if let Some((environment, rest)) = table_environment {
|
||||
if let Some((template, _)) = braced(rest.trim_start()) {
|
||||
if !body.ends_with('\n') {
|
||||
body.push('\n');
|
||||
}
|
||||
body.push_str(&format!("\\texrratable{{{}}}\n", geometry.tabular.len()));
|
||||
tabular = Some((template.to_string(), String::new()));
|
||||
tabular = Some((template.to_string(), String::new(), environment));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -1368,7 +1376,7 @@ fn strip_page_geometry(source: &str) -> (String, PageGeometry) {
|
||||
body.push('\n');
|
||||
}
|
||||
}
|
||||
if let Some((template, text)) = tabular {
|
||||
if let Some((template, text, _)) = tabular {
|
||||
geometry.tabular.push((template, text));
|
||||
}
|
||||
(body, geometry)
|
||||
@@ -6926,6 +6934,17 @@ See \ref{fig:a} and \ref{tab:b}.";
|
||||
assert_eq!(blocks[1].space_before, 5, "12pt itemsep");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn longtable_captures_its_body() {
|
||||
let (body, geometry) =
|
||||
geometry_and_body("\\begin{longtable}{ll}\na & b \\\\\n\\end{longtable}\n\nBody.");
|
||||
assert_eq!(geometry.tabular.len(), 1);
|
||||
assert_eq!(geometry.tabular[0].0, "ll");
|
||||
assert!(geometry.tabular[0].1.contains("a & b"));
|
||||
assert!(body.contains("\\texrratable{0}"));
|
||||
assert!(!body.contains("longtable"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rule_paragraphs_become_rule_boxes() {
|
||||
let blocks = paragraphs("\\rule{20pt}{5pt}").expect("rule");
|
||||
|
||||
Reference in new issue
Block a user