Skip to content

A fast, helpful, and open-source document parser

wip

Logan Markewichd0b21f21a492
diff --git a/crates/liteparse/src/extract.rs b/crates/liteparse/src/extract.rs
index c6cdf16..806aba1 100644
--- a/crates/liteparse/src/extract.rs
+++ b/crates/liteparse/src/extract.rs
@@ -137,10 +137,12 @@ pub(crate) fn extract_pages_and_images(
extract_page_image_refs(&page, page_number, output_options.extract_images);
let mut image_refs = extracted_refs.refs;
image_error_count += extracted_refs.error_count;
- let pdf_annotations = (output_options.extract_annotations
- || output_options.extract_structure_tree)
- .then(|| page.annotations(&view_box))
- .unwrap_or_default();
+ let pdf_annotations =
+ if output_options.extract_annotations || output_options.extract_structure_tree {
+ page.annotations(&view_box)
+ } else {
+ Default::default()
+ };
let annotations = output_options
.extract_annotations
.then(|| pdf_annotations.iter().map(document_annotation).collect());
diff --git a/crates/liteparse/src/markdown_layout/tables.rs b/crates/liteparse/src/markdown_layout/tables.rs
index dbd6413..7d109b6 100644
--- a/crates/liteparse/src/markdown_layout/tables.rs
+++ b/crates/liteparse/src/markdown_layout/tables.rs
@@ -1634,7 +1634,7 @@ pub(crate) fn validated_ruled_table_rects(
x1 = x1.max(b.x + b.width);
y1 = y1.max(b.y + b.height);
}
- (x1 > x0 && y1 > y0).then(|| Rect {
+ (x1 > x0 && y1 > y0).then_some(Rect {
x: x0,
y: y0,
width: x1 - x0,
@@ -4836,20 +4836,20 @@ fn merge_continuation_rows(rows: &mut Vec<Vec<String>>) {
}
let mut out: Vec<Vec<String>> = Vec::with_capacity(rows.len());
for row in rows.drain(..) {
- if let Some(prev) = out.last_mut() {
- if is_continuation_row(prev, &row) {
- for (i, cell) in row.iter().enumerate() {
- let t = cell.trim();
- if t.is_empty() {
- continue;
- }
- // `prev[i]` is non-empty for every filled column of `row`;
- // that is the subset rule `is_continuation_row` enforces.
- prev[i].push(' ');
- prev[i].push_str(t);
+ if let Some(prev) = out.last_mut()
+ && is_continuation_row(prev, &row)
+ {
+ for (i, cell) in row.iter().enumerate() {
+ let t = cell.trim();
+ if t.is_empty() {
+ continue;
}
- continue;
+ // `prev[i]` is non-empty for every filled column of `row`;
+ // that is the subset rule `is_continuation_row` enforces.
+ prev[i].push(' ');
+ prev[i].push_str(t);
}
+ continue;
}
out.push(row);
}
diff --git a/crates/liteparse/src/office/docx.rs b/crates/liteparse/src/office/docx.rs
index 7f3aaa9..8a79dc5 100644
--- a/crates/liteparse/src/office/docx.rs
+++ b/crates/liteparse/src/office/docx.rs
@@ -487,7 +487,7 @@ impl<'a> Emitter<'a> {
// Emitted as declared. A dense 1..N remap was measured on the
// 48-doc corpus and lost 39 of 66 heading rules; see the
// "heading levels" note in NATIVE_OFFICE_PLAN.md.
- level: OutlineLevel::value(lvl).clamp(1, 6) as u8,
+ level: OutlineLevel::value(lvl).clamp(1, 6),
text: self.escape(text.trim()),
});
self.flush_pending(out);