use super::*;
pub(super) fn walk_container(
ctx: &WalkCtx<'_>,
dom: &Dom,
node: NodeId,
numbering: &mut Numbering,
blocks: &mut Vec<Block>,
endnotes: &mut EndnoteBag,
) {
let mut frame: Option<(String, Vec<NodeId>)> = None;
let mut frame_boxes: Vec<LaidTextBox> = Vec::new();
let count = dom.child_count(node);
for idx in 0..=count {
let child = (idx < count).then(|| dom.child_at(node, idx));
let key = child
.filter(|c| dom.name_is(*c, &W::p()))
.and_then(|c| body_frame_key(dom, c, ctx.sheet));
if let Some((k, _)) = frame.as_ref()
&& key.as_deref() != Some(k.as_str())
{
let (_, paras) = frame.take().expect("a frame");
if let Some(b) = frame_box(ctx, dom, ¶s, numbering) {
frame_boxes.push(b);
}
}
if let (Some(c), Some(k)) = (child, key) {
frame.get_or_insert_with(|| (k, Vec::new())).1.push(c);
continue;
}
let Some(child) = child else {
break;
};
if dom.name_is(child, &W::comment_range_start()) {
if let Some(id) = attr_any(dom, child, "id") {
let mut open = ctx.open_comments.borrow_mut();
if !open.iter().any(|o| o == id) {
open.push(id.to_string());
}
}
continue;
}
if dom.name_is(child, &W::comment_range_end()) {
if let Some(id) = attr_any(dom, child, "id") {
ctx.open_comments.borrow_mut().retain(|o| o != id);
}
continue;
}
if dom.name_is(child, &W::p()) {
if para_base(dom, child, ctx.sheet, None).0.page_break_before && !blocks.is_empty() {
blocks.push(Block::PageBreak {
next: None,
manual: false,
mark_after: None,
});
}
let page_br = para_has_page_break(dom, child);
let column_br = para_has_column_break(dom, child);
let sect_here = para_sect_pr(dom, child);
let sect_br = sect_here.is_some_and(|s| {
!is_final_sect(ctx.sects, s)
&& next_sect_pr(ctx.sects, s).is_none_or(|n| {
let base = &ctx.sheet.defaults.page;
let (was, page) =
(apply_sect_pr(dom, s, base), apply_sect_pr(dom, n, base));
sect_starts_new_page(dom, n)
|| (was.width - page.width).abs() > 0.5
|| (was.height - page.height).abs() > 0.5
})
});
endnotes.observe_para(dom, child);
let mut block = paragraph_block(ctx, dom, child, false, numbering);
if let Block::Paragraph {
runs,
images,
boxes,
..
} = &block
&& frame_boxes.is_empty()
&& images.is_empty()
&& boxes.is_empty()
&& runs.iter().all(|r| r.text.trim().is_empty())
&& sect_here.is_none()
&& !page_br
&& !column_br
&& para_mark_hidden(dom, child, &ctx.sheet.by_id)
{
continue;
}
if let Block::Paragraph { boxes, .. } = &mut block {
boxes.append(&mut frame_boxes);
}
let break_mark = if column_br {
COLUMN_BREAK_MARK
} else {
PAGE_BREAK_MARK
};
let break_run = match &block {
Block::Paragraph { runs, .. } => runs
.iter()
.rev()
.find(|r| r.text.contains(break_mark))
.map(|r| r.style.clone()),
_ => None,
};
let media_after = drawings_follow_page_break(dom, child);
let (mut parts, seps, trailing) =
split_page_breaks(block, page_br, column_br, media_after);
let (page_br, column_br) = (trailing == Some(false), trailing == Some(true));
let block = parts.pop().expect("split keeps the paragraph");
for (i, (part, column)) in parts.into_iter().zip(seps).enumerate() {
let bookmarked =
matches!(&part, Block::Paragraph { bookmarks, .. } if !bookmarks.is_empty());
if !(i == 0 && block_is_blank(&part) && (column || !bookmarked)) {
blocks.push(part);
}
blocks.push(if column {
Block::ColumnBreak
} else {
Block::PageBreak {
next: None,
manual: true,
mark_after: None,
}
});
}
let column_mark = match &block {
Block::Paragraph { style, .. } if column_br => {
let style = style.clone();
let runs = style
.mark_run
.as_deref()
.map(|m| vec![TextRun::new(" ", m.clone())])
.unwrap_or_default();
Some(Block::Paragraph {
runs,
style,
list: false,
images: Vec::new(),
boxes: Vec::new(),
bookmarks: Vec::new(),
})
}
_ => None,
};
let blank = block_is_blank(&block);
let sect_mark = sect_here.is_some_and(|s| !is_final_sect(ctx.sects, s))
&& !(blocks.is_empty() && !page_br && !column_br);
let mark_after = match &block {
Block::Paragraph { style, .. } if blank && sect_mark => Some(style.after),
_ => None,
};
if !blank || (!page_br && !sect_br && !column_br && !sect_mark) {
blocks.push(block);
} else if (column_br || (page_br && sect_here.is_none()))
&& let (Some(run_style), Block::Paragraph { style, .. }) = (break_run, &block)
&& settings_compat_mode(ctx.pkg) >= 15
{
let mut style = style.clone();
style.before = 0.0;
style.before_auto = false;
style.after = 0.0;
style.after_auto = false;
blocks.push(Block::Paragraph {
runs: vec![TextRun::new(" ", run_style)],
style,
list: false,
images: Vec::new(),
boxes: Vec::new(),
bookmarks: Vec::new(),
});
}
if let Some(s) = sect_here.filter(|s| !is_final_sect(ctx.sects, *s)) {
endnotes.flush_if_sect_end(ctx, dom, s, numbering, blocks);
}
if page_br || sect_br {
let next = if sect_br {
sect_here
.and_then(|s| next_sect_pr(ctx.sects, s))
.map(|s| Box::new(section_chrome(ctx.pkg, ctx.main, dom, s, ctx.sheet)))
} else {
None
};
blocks.push(Block::PageBreak {
next,
manual: page_br,
mark_after,
});
} else if column_br {
blocks.push(Block::ColumnBreak);
blocks.extend(column_mark);
}
if !sect_br
&& let Some(here) = sect_here.filter(|s| !is_final_sect(ctx.sects, *s))
&& let Some(next) = next_sect_pr(ctx.sects, here)
{
let base = &ctx.sheet.defaults.page;
let (was, page) = (
apply_sect_pr(dom, here, base),
apply_sect_pr(dom, next, base),
);
let cols = |p: &PageSetup| {
(
p.col_count.max(1),
p.col_custom,
p.col_w,
p.col_gap,
p.col_sep,
)
};
let moved = cols(&was) != cols(&page)
|| (page.col_count > 1 && (was.col_space - page.col_space).abs() > 0.01)
|| (was.margin_l - page.margin_l).abs() > 0.01
|| (was.margin_r - page.margin_r).abs() > 0.01
|| (was.margin_t - page.margin_t).abs() > 0.01
|| (was.margin_b - page.margin_b).abs() > 0.01;
if moved {
blocks.push(Block::SectionCols {
page: Box::new(page),
});
}
}
} else if dom.name_is(child, &W::tbl()) {
endnotes.observe_para(dom, child);
let block = table_block(
dom,
child,
ctx.sheet,
numbering,
&mut ctx.authors.borrow_mut(),
&ctx.comments,
Some((ctx.pkg, ctx.main)),
);
if !block_is_blank(&block) {
blocks.push(block);
}
} else if local_name_is(dom, child, "customXml") {
walk_container(ctx, dom, child, numbering, blocks, endnotes);
} else if dom.name_is(child, &W::sdt())
&& let Some(content) = dom.element(child, &W::sdt_content())
{
if is_cover_pages_sdt(dom, child)
&& !blocks.is_empty()
&& !matches!(blocks.last(), Some(Block::PageBreak { .. }))
{
blocks.push(Block::PageBreak {
next: None,
manual: false,
mark_after: None,
});
}
walk_container(ctx, dom, content, numbering, blocks, endnotes);
} else if dom.name_is(child, &W::sect_pr()) && !is_final_sect(ctx.sects, child) {
endnotes.flush_if_sect_end(ctx, dom, child, numbering, blocks);
if next_sect_pr(ctx.sects, child).is_none_or(|n| sect_starts_new_page(dom, n)) {
let next = next_sect_pr(ctx.sects, child)
.map(|s| Box::new(section_chrome(ctx.pkg, ctx.main, dom, s, ctx.sheet)));
blocks.push(Block::PageBreak {
next,
manual: false,
mark_after: None,
});
}
}
}
}
pub(super) fn page_frame_key(dom: &Dom, para: NodeId, sheet: &StyleSheet) -> Option<String> {
let fp = para_frame_attrs(dom, para, sheet)?;
let attr = |n: &str| frame_attr(&fp, n).unwrap_or("").to_string();
(attr("hAnchor") == "page"
&& attr("vAnchor") == "page"
&& !attr("x").is_empty()
&& !attr("y").is_empty())
.then(|| {
["x", "y", "w", "h", "hRule", "wrap", "hSpace", "vSpace"]
.iter()
.map(|n| attr(n))
.collect::<Vec<_>>()
.join("|")
})
}
pub(super) fn body_frame_key(dom: &Dom, para: NodeId, sheet: &StyleSheet) -> Option<String> {
page_frame_key(dom, para, sheet).or_else(|| {
let fp = para_frame_attrs(dom, para, sheet)?;
let attr = |n: &str| frame_attr(&fp, n).unwrap_or("").to_string();
let h_anchor = attr("hAnchor");
let beside_text = attr("vAnchor") == "text"
&& matches!(h_anchor.as_str(), "page" | "margin" | "text")
&& attr("wrap") == "around"
&& !attr("x").is_empty();
let on_page = attr("vAnchor") == "page"
&& matches!(h_anchor.as_str(), "margin" | "text")
&& matches!(attr("wrap").as_str(), "around" | "")
&& (!attr("x").is_empty() || attr("xAlign").is_empty());
let aligned = attr("y").is_empty()
&& matches!(attr("yAlign").as_str(), "top" | "center" | "bottom")
&& matches!(attr("vAnchor").as_str(), "" | "margin" | "page")
&& matches!(h_anchor.as_str(), "" | "page" | "margin" | "text")
&& matches!(attr("wrap").as_str(), "around" | "")
&& (!attr("x").is_empty() || attr("xAlign").is_empty());
((beside_text || on_page) && !attr("y").is_empty() || aligned).then(|| {
[
"vAnchor", "hAnchor", "x", "y", "yAlign", "w", "h", "hRule", "hSpace", "vSpace",
]
.iter()
.map(|n| attr(n))
.collect::<Vec<_>>()
.join("|")
})
})
}
pub(super) fn hf_text_frame_key(dom: &Dom, para: NodeId, sheet: &StyleSheet) -> Option<String> {
page_frame_key(dom, para, sheet).filter(|_| {
dom.descendants(para, Some(&W::drawing())).is_empty()
&& dom.descendants(para, Some(&W::pict())).is_empty()
})
}
pub(super) fn merge_frame_attrs(dom: &Dom, fp: NodeId, out: &mut Vec<(String, String)>) {
for (name, value) in dom.attributes(fp) {
let local = name.local_name().to_string();
match out.iter_mut().find(|(n, _)| *n == local) {
Some(slot) => slot.1 = value,
None => out.push((local, value)),
}
}
}
pub(super) fn para_frame_attrs(
dom: &Dom,
para: NodeId,
sheet: &StyleSheet,
) -> Option<Vec<(String, String)>> {
let ppr = dom.element(para, &W::p_pr());
let sid = ppr
.and_then(|ppr| first_named(dom, ppr, "pStyle"))
.and_then(|ps| attr_any(dom, ps, "val"))
.unwrap_or(sheet.defaults.para.style_id.as_str());
let mut attrs = sheet
.by_id
.get(sid)
.filter(|n| !n.not_para)
.map(|n| n.frame.clone())
.unwrap_or_default();
let own = ppr.and_then(|ppr| first_named(dom, ppr, "framePr"));
if let Some(fp) = own {
merge_frame_attrs(dom, fp, &mut attrs);
}
(own.is_some() || !attrs.is_empty()).then_some(attrs)
}
pub(super) fn frame_attr<'a>(attrs: &'a [(String, String)], name: &str) -> Option<&'a str> {
attrs
.iter()
.find(|(n, _)| n == name)
.map(|(_, v)| v.as_str())
}
pub(super) fn frame_box(
ctx: &WalkCtx<'_>,
dom: &Dom,
paras: &[NodeId],
numbering: &mut Numbering,
) -> Option<LaidTextBox> {
let first = *paras.first()?;
let fp = para_frame_attrs(dom, first, ctx.sheet)?;
let tw = |n: &str| {
frame_attr(&fp, n)
.and_then(parse_finite_f32)
.map(|v| v / 20.0)
};
let v_align = match frame_attr(&fp, "yAlign") {
Some("top") => Some(Align::Left),
Some("center") => Some(Align::Center),
Some("bottom") => Some(Align::Right),
_ => None,
};
let x = tw("x").unwrap_or(0.0);
let set_y = tw("y");
let by_align = set_y.is_none();
if by_align {
v_align?;
}
let y = set_y.unwrap_or(0.0);
let mut laid = Vec::new();
let mut outline: Option<([f32; 3], f32)> = None;
for &p in paras {
if let Block::Paragraph {
runs, mut style, ..
} = paragraph_block(ctx, dom, p, false, numbering)
{
if outline.is_none()
&& let Some((color, width, _)) = style.border_top.or(style.border_left)
{
outline = Some((color, width));
}
style.border_top = None;
style.border_bottom = None;
style.border_left = None;
style.border_right = None;
laid.push((runs, style));
}
}
let line_guess: f32 = laid
.iter()
.map(|(runs, style)| runs_size(runs).max(10.0) * 1.2 * style.line_mult.max(1.0))
.sum();
let w = tw("w").unwrap_or(144.0);
let auto_w = tw("w").is_none_or(|w| w <= 0.0);
let auto_h = tw("h").is_none_or(|h| h <= 0.0);
let content: f32 = laid
.iter()
.map(|(runs, style)| {
let line = style
.line_exact
.unwrap_or(runs_size(runs).max(10.0) * 1.15 * style.line_mult.max(1.0))
.max(style.line_at_least.unwrap_or(0.0));
line + style.before + style.after
})
.sum();
let h = match tw("h").filter(|h| *h > 0.0) {
Some(h) if frame_attr(&fp, "hRule") == Some("exact") => h,
Some(h) => h.max(content),
None => line_guess,
};
let around = frame_attr(&fp, "wrap").is_none_or(|v| v == "around");
let h_space = tw("hSpace").unwrap_or(0.0);
let v_space = tw("vSpace").unwrap_or(0.0);
let h_anchor = frame_attr(&fp, "hAnchor").unwrap_or("page");
let on_text = frame_attr(&fp, "vAnchor") == Some("text");
let h_page = h_anchor == "page";
Some(LaidTextBox {
w,
h,
runs: Vec::new(),
slot: ImageSlot::Float {
align: Align::Left,
page_x: h_page.then_some(x),
page_y: (!on_text && !by_align).then_some(y),
col_x: (!h_page).then_some(x),
col_in_column: h_anchor == "text",
para_y: (on_text && !by_align).then_some(y),
pct_x: None,
pct_y: None,
pct_w: None,
pct_h: None,
v_align: v_align.filter(|_| by_align).unwrap_or(Align::Left),
wrap_square: around,
wrap_top_bottom: false,
wrap_polygon: false,
poly_bottom: 1.0,
dist_l: h_space,
dist_r: h_space,
dist_t: v_space,
dist_b: v_space,
effect_b: 0.0,
h_rel: match h_anchor {
"margin" => RelFrame::Margin,
"text" => RelFrame::Column,
_ => RelFrame::Page,
},
v_rel: if on_text {
RelFrame::Paragraph
} else if by_align && frame_attr(&fp, "vAnchor") != Some("page") {
RelFrame::Margin
} else {
RelFrame::Page
},
v_off: None,
},
chart: None,
stroke: outline.is_some(),
fill: None,
line: outline.map(|o| o.0),
line_width: outline.map_or(0.75, |o| o.1),
geom: ShapeGeom::Box,
reserve_only: false,
behind: false,
z: 0,
flip_h: false,
flip_v: false,
tail_end: false,
diag_shapes: Vec::new(),
text_dx: 0.0,
text_dy: 0.0,
text_anchor: TextAnchor::Top,
adj: Vec::new(),
prst: String::new(),
paras: laid,
tables: Vec::new(),
insets: if outline.is_some() {
[1.0; 4]
} else {
[0.0; 4]
},
custom: None,
group: Vec::new(),
chrome_para_top: 0.0,
fit_width: auto_w,
fit_height: auto_h,
raise: 0.0,
frame: true,
vml: false,
})
}
fn drawings_follow_page_break(dom: &Dom, para: NodeId) -> bool {
let nodes = dom.descendants(para, None);
let Some(br) = nodes
.iter()
.position(|n| dom.name_is(*n, &W::name("br")) && attr_any(dom, *n, "type") == Some("page"))
else {
return false;
};
let mut drawings = nodes
.iter()
.enumerate()
.filter(|(_, n)| dom.name_is(**n, &W::drawing()) || dom.name_is(**n, &W::pict()))
.peekable();
drawings.peek().is_some() && drawings.all(|(i, _)| i > br)
}
pub(super) fn split_page_breaks(
block: Block,
page_br: bool,
column_br: bool,
media_after: bool,
) -> (Vec<Block>, Vec<bool>, Option<bool>) {
let fallback = if page_br {
Some(false)
} else {
column_br.then_some(true)
};
let Block::Paragraph {
runs,
style,
list,
images,
boxes,
bookmarks,
} = block
else {
return (vec![block], Vec::new(), fallback);
};
if !runs.iter().any(|r| r.text.contains(is_break_mark)) {
return (
vec![Block::Paragraph {
runs,
style,
list,
images,
boxes,
bookmarks,
}],
Vec::new(),
fallback,
);
}
let mut pieces: Vec<Vec<TextRun>> = vec![Vec::new()];
let mut seps: Vec<bool> = Vec::new();
for run in runs {
let mut start = 0;
for (at, c) in run.text.char_indices().filter(|(_, c)| is_break_mark(*c)) {
if at > start {
pieces
.last_mut()
.expect("a piece")
.push(run.with_text(&run.text[start..at]));
}
seps.push(c == COLUMN_BREAK_MARK);
pieces.push(Vec::new());
start = at + c.len_utf8();
}
if start < run.text.len() {
pieces
.last_mut()
.expect("a piece")
.push(run.with_text(&run.text[start..]));
}
}
let ink = |p: &[TextRun]| p.iter().any(|r| !r.text.trim().is_empty() || r.list_marker);
let media = media_after && !(images.is_empty() && boxes.is_empty());
let last_ink = if media {
pieces.len() - 1
} else {
pieces.iter().rposition(|p| ink(p)).unwrap_or(0)
};
let media_at = if media { last_ink } else { 0 };
let trailing = (last_ink + 1 < pieces.len()).then(|| seps[last_ink]);
pieces.truncate(last_ink + 1);
seps.truncate(last_ink);
let n = pieces.len();
let mut images = Some(images);
let mut boxes = Some(boxes);
let mut bookmarks = Some(bookmarks);
let parts = pieces
.into_iter()
.enumerate()
.map(|(i, runs)| {
let mut style = style.clone();
if i > 0 {
style.before = 0.0;
style.before_auto = false;
}
if i + 1 < n {
style.after = 0.0;
style.after_auto = false;
}
Block::Paragraph {
runs,
style,
list: list && i == 0,
images: if i == media_at {
images.take().unwrap_or_default()
} else {
Vec::new()
},
boxes: if i == media_at {
boxes.take().unwrap_or_default()
} else {
Vec::new()
},
bookmarks: if i == 0 {
bookmarks.take().unwrap_or_default()
} else {
Vec::new()
},
}
})
.collect();
(parts, seps, trailing)
}
fn para_sect_pr(dom: &Dom, para: NodeId) -> Option<NodeId> {
let ppr = dom.element(para, &W::p_pr())?;
first_named(dom, ppr, "sectPr")
}
fn para_has_page_break(dom: &Dom, para: NodeId) -> bool {
for br in dom.descendants(para, Some(&W::name("br"))) {
if let Some(kind) = dom.attribute(br, &W::type_())
&& (kind == "page" || kind == "oddPage" || kind == "evenPage")
{
return true;
}
}
false
}
fn para_has_column_break(dom: &Dom, para: NodeId) -> bool {
for br in dom.descendants(para, Some(&W::name("br"))) {
if dom.attribute(br, &W::type_()) == Some("column") {
return true;
}
}
false
}
fn sect_starts_new_page(dom: &Dom, sect: NodeId) -> bool {
!matches!(
first_named(dom, sect, "type").and_then(|n| dom.attribute(n, &W::val())),
Some("continuous")
)
}
pub(super) fn block_para_style(block: &Block) -> Option<&ParaStyle> {
match block {
Block::Paragraph { style, .. } => Some(style),
Block::Table { .. }
| Block::PageBreak { .. }
| Block::ColumnBreak
| Block::SectionCols { .. } => None,
}
}
pub(super) fn contextual_gap(prev: &ParaStyle, next: &ParaStyle, after: f32, before: f32) -> f32 {
let own_after = if same_contextual_pair(prev, next) {
0.0
} else {
after
};
let own_before = if same_contextual_pair(next, prev) {
0.0
} else {
before_past(before, after, next.sum_spacing)
};
own_after + own_before
}
pub(super) fn before_past(before: f32, after: f32, sum: bool) -> f32 {
if sum {
before
} else {
(before - after).max(0.0)
}
}
pub(super) fn same_contextual_pair(left: &ParaStyle, right: &ParaStyle) -> bool {
left.contextual && left.style_id == right.style_id
}
pub(super) fn leftover_break_heading(style_id: &str) -> bool {
style_id.to_ascii_lowercase().starts_with("textheading")
}
pub(super) fn para_line_box(metrics: &Face, size: f32, style: &ParaStyle) -> f32 {
let size = if size > 0.0 { size } else { 11.0 };
line_box_from_natural(metrics.single_line_pt(size), style)
}
pub(super) fn grid_line_box(natural: f32, style: &ParaStyle, grid: f32) -> f32 {
let multiple = style.line_exact.is_none() && style.line_at_least.is_none();
if grid > 0.5 && multiple && natural <= grid + 0.01 {
let m = if style.line_mult > 0.0 {
style.line_mult
} else {
1.0
};
grid * m
} else if grid > 0.5 && multiple {
let m = if style.line_mult > 0.0 {
style.line_mult
} else {
1.0
};
snap_doc_grid(natural, grid).max(grid * m)
} else {
snap_doc_grid(line_box_from_natural(natural, style), grid)
}
}
pub(super) fn line_box_from_natural(natural: f32, style: &ParaStyle) -> f32 {
if let Some(exact) = style.line_exact {
exact
} else if let Some(at_least) = style.line_at_least {
natural.max(at_least)
} else {
let m = if style.line_mult > 0.0 {
style.line_mult
} else {
1.0
};
natural * m
}
}
pub(super) fn shaped_lacks_ink(chars: &[char], shaped: &[(u16, f32)]) -> bool {
if chars.len() == shaped.len() {
chars
.iter()
.zip(shaped.iter())
.any(|(ch, (gid, _))| !ch.is_whitespace() && *gid == 0)
} else {
chars.iter().any(|ch| !ch.is_whitespace()) && shaped.iter().any(|(gid, _)| *gid == 0)
}
}
pub(super) fn face_lacks_ink(face: &Face, text: &str) -> bool {
let chars: Vec<char> = text.chars().collect();
shaped_lacks_ink(&chars, &face.shape(text, 11.0))
}
pub(super) fn ink_face(fonts: &Fonts, style: &RunStyle, text: &str) -> FaceRef {
let fid = fonts.resolve(paint_family(style, text), style.bold, style.italic);
let script = text.chars().any(takes_script_fallback);
if !script || !face_lacks_ink(fonts.get(fid), text) {
return fid;
}
match script_glyph_fallback(fonts, style, text) {
Some(cjk) => cjk,
None if style.bold => FaceId::SansBold.into(),
None => FaceId::SansRegular.into(),
}
}
pub(super) struct PicLine {
pub(super) only: bool,
pub(super) h: f32,
pub(super) under: f32,
pub(super) extra: f32,
}
pub(super) fn line_fit_need(natural: f32, ascent: f32, style: &ParaStyle, line_box: f32) -> f32 {
if style.line_exact.is_some() {
return line_box;
}
let need = if style.line_at_least.is_none() {
line_box.min(natural)
} else {
line_box
};
need.max(ascent + 2.0)
}
pub(super) fn is_toc_style(style: &ParaStyle) -> bool {
let id = style.style_id.to_ascii_lowercase();
id.starts_with("sumrio") || id.starts_with("sumario") || id.starts_with("toc")
}
pub(super) fn para_is_empty_toc_field(dom: &Dom, para: NodeId) -> bool {
let mut saw_toc = false;
for n in dom.descendants(para, Some(&W::instr_text())) {
if element_text(dom, n).to_ascii_uppercase().contains("TOC") {
saw_toc = true;
break;
}
}
if !saw_toc {
return false;
}
!dom.descendants(para, Some(&W::t()))
.into_iter()
.any(|n| !element_text(dom, n).trim().is_empty())
}
pub(super) fn table_joins_previous(blocks: &[Block], i: usize) -> bool {
let Some(Block::Table { geom, .. }) = blocks.get(i) else {
return false;
};
geom.float.is_none()
&& i.checked_sub(1).is_some_and(|j| {
matches!(&blocks[j], Block::Table { geom: prev, .. }
if prev.float.is_none()
&& prev.fixed == geom.fixed
&& prev.style_id == geom.style_id)
})
}