diff --git a/src/formats/docx/content.rs b/src/formats/docx/content.rs index c5a7c18b..ff2a1934 100644 --- a/src/formats/docx/content.rs +++ b/src/formats/docx/content.rs @@ -502,6 +502,9 @@ impl<'a, 'b, 'e> InlineWalker<'a, 'b, 'e> { } } "tab" | "ptab" => self.push(Inline::Text { text: " ".into(), style: Style::PLAIN }), + // A non-breaking hyphen is a visible hyphen, the one the + // binary and RTF readers emit for the same character. + "noBreakHyphen" => self.push(Inline::Text { text: "-".into(), style }), // Markdown has no pages or columns, but every w:br still // separates the runs around it: dropping a page break // outright would join the words on either side. One left at diff --git a/src/formats/docx/mod.rs b/src/formats/docx/mod.rs index eee5317e..bccf5391 100644 --- a/src/formats/docx/mod.rs +++ b/src/formats/docx/mod.rs @@ -287,6 +287,18 @@ mod tests { } } + #[test] + fn non_breaking_hyphen_renders_as_a_hyphen() { + // Word writes a non-breaking hyphen as its own run element; dropping + // it joins the text on either side. + let document = format!( + r#"Call 5550123 by email"# + ); + let bytes = docx_parts(&[("word/document.xml", &document)]); + let markdown = crate::to_markdown_bytes(&bytes, crate::Format::Docx).unwrap(); + assert_eq!(markdown, "Call 555-0123 by e-mail\n"); + } + #[test] fn numbered_heading_keeps_its_number() { // H1: a heading style with numbering shows its label and advances