Skip to content

Commit d401ca4

Browse files
committed
test(HTML): add failing regression test for block-in-inline epub
Change-Id: 7e3d38a0c96bff76e1278d669589601e Change-Id-Short: slwmwrpznqto
1 parent 7b6062b commit d401ca4

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

crates/core/src/document/epub/mod.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,52 @@ mod tests {
12351235
);
12361236
}
12371237

1238+
/// Reproduces https://github.com/baskerville/plato/issues/426:
1239+
/// EPUB files from royallib.com wrap block elements inside inline `<span>`
1240+
/// ancestors. The engine's `has_blocks` check only looks at direct children,
1241+
/// so the outer `<span>` appears inline-only, `gather_inline_material`
1242+
/// recurses into it, and the nested `<div>`/`<p>` bodies are silently
1243+
/// dropped — only the chapter title renders.
1244+
///
1245+
/// Spine index 39 is OPS/ch1-38.xhtml. Its body starts with:
1246+
/// <span><span><span id="id90">
1247+
/// <div class="title6"><p>"Коса" жизни</p></div>
1248+
/// <p>Георгий Гамов озаглавил …</p>
1249+
/// …
1250+
/// The first body paragraph is the canary: if block-in-inline
1251+
/// promotion is broken, gather_inline_material swallows the <p>
1252+
/// nodes and this text never appears in any DrawCommand.
1253+
#[test]
1254+
fn royallib_block_in_inline_renders_body_paragraphs() {
1255+
let root_dir = PathBuf::from(
1256+
std::env::var("TEST_ROOT_DIR").expect("TEST_ROOT_DIR must be set for epub tests"),
1257+
);
1258+
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
1259+
let epub_path =
1260+
manifest_dir.join("src/document/tests/fixtures/royallib-block-in-inline.epub");
1261+
1262+
let mut doc = EpubDocumentFile::new(&epub_path).expect("failed to open royallib epub");
1263+
doc.engine.layout(600, 800, 12.0, 265);
1264+
doc.engine.set_margin_width(3);
1265+
doc.engine.load_fonts_from(root_dir);
1266+
1267+
let display_list = doc.build_display_list(39, 0);
1268+
1269+
let rendered_text: String = display_list
1270+
.iter()
1271+
.flat_map(|page| page.iter())
1272+
.filter_map(|cmd| match cmd {
1273+
DrawCommand::Text(tc) | DrawCommand::ExtraText(tc) => Some(tc.text.as_str()),
1274+
_ => None,
1275+
})
1276+
.collect();
1277+
1278+
assert!(
1279+
rendered_text.contains("Георгий") && rendered_text.contains("Гамов"),
1280+
"body paragraph text not rendered — block-in-inline content was silently dropped",
1281+
);
1282+
}
1283+
12381284
#[test]
12391285
fn all_spine_chapters_produce_content() {
12401286
let mut doc = setup_epub();
Binary file not shown.

0 commit comments

Comments
 (0)