|
| 1 | +//! Regression test for #117 — `--keep-original-links` on Google Docs API |
| 2 | +//! exports stripped every image entirely because the HTML export emits |
| 3 | +//! `<img alt="" src="data:image/png;base64,...">`, the markdown converter |
| 4 | +//! rendered that as ``, and the strip helper only emitted a |
| 5 | +//! placeholder when `alt` was non-empty. The result was a silently |
| 6 | +//! image-less document with no indication that anything was lost. |
| 7 | +
|
| 8 | +use web_capture::extract_images::strip_base64_images; |
| 9 | + |
| 10 | +// 1x1 red PNG pixel as base64. |
| 11 | +const TINY_PNG: &str = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=="; |
| 12 | + |
| 13 | +#[test] |
| 14 | +fn strip_keeps_a_visible_placeholder_for_empty_alt() { |
| 15 | + let md = format!("P1.\n\n\n\nP2.\n"); |
| 16 | + let r = strip_base64_images(&md); |
| 17 | + assert_eq!(r.stripped, 1); |
| 18 | + assert!(!r.markdown.contains("data:image")); |
| 19 | + assert!( |
| 20 | + r.markdown.contains("![") || r.markdown.contains("[image"), |
| 21 | + "stripping must leave a visible placeholder; got:\n{}", |
| 22 | + r.markdown |
| 23 | + ); |
| 24 | +} |
| 25 | + |
| 26 | +#[test] |
| 27 | +fn strip_keeps_empty_alt_placeholder_distinct_from_non_empty_alt() { |
| 28 | + // Non-empty alt still produces the `*[image: ...]*` form so authors can |
| 29 | + // read the alt text. Empty alt produces a structural placeholder so a |
| 30 | + // human can still tell that an image was here. |
| 31 | + let md = format!( |
| 32 | + "\n\n\n" |
| 33 | + ); |
| 34 | + let r = strip_base64_images(&md); |
| 35 | + assert_eq!(r.stripped, 2); |
| 36 | + assert!(!r.markdown.contains("data:image")); |
| 37 | + assert!(r.markdown.contains("*[image: photo]*")); |
| 38 | + // Empty-alt branch leaves an `` style placeholder, so the line |
| 39 | + // count (and image count, when grepping for `![`) is preserved. |
| 40 | + let placeholder_count = r.markdown.matches("![").count(); |
| 41 | + assert!( |
| 42 | + placeholder_count >= 1, |
| 43 | + "expected at least one `![` placeholder for the empty-alt image; got:\n{}", |
| 44 | + r.markdown |
| 45 | + ); |
| 46 | +} |
0 commit comments