diff --git a/gemtext/src/lib.rs b/gemtext/src/lib.rs index 504b5ed..04d94e8 100644 --- a/gemtext/src/lib.rs +++ b/gemtext/src/lib.rs @@ -205,7 +205,13 @@ fn is_only_links(inline: &[Inline]) -> bool { match item { Inline::Link { .. } | Inline::Image { .. } => saw_link = true, Inline::Text(text) if text.trim().is_empty() => {} - Inline::SoftBreak => {} + // Either break kind. A hard break between links is still a run of + // nothing but links, and a generator has good reason to use one: + // the formats that lay links out inline need
to stop a menu + // running together on one line, and refusing it here would make + // the paragraph print its flattened text as well as the => lines, + // listing every entry twice. + Inline::SoftBreak | Inline::HardBreak => {} _ => return false, } } @@ -300,6 +306,16 @@ mod tests { use super::tests_support::render; use super::*; + #[test] + fn a_hard_break_between_links_still_lifts_them() { + // Generators emit hard breaks so the inline formats put each link on + // its own line. gemtext must not read that as prose and print the + // flattened text alongside the => lines, which would list every entry + // twice. + let out = render("[one](/a) \n[two](/b)\n"); + assert_eq!(out, "=> /a one\n=> /b two\n"); + } + #[test] fn headings_flatten_onto_three_levels() { assert_eq!(render("# a\n## b\n### c\n#### d\n"), "# a\n\n## b\n\n### c\n\n### d\n");