diff --git a/mdast_util_to_markdown/src/state.rs b/mdast_util_to_markdown/src/state.rs index 7a0b5c3..56648ac 100644 --- a/mdast_util_to_markdown/src/state.rs +++ b/mdast_util_to_markdown/src/state.rs @@ -535,6 +535,12 @@ impl<'a> State<'a> { }; } + // Some of the operations above seem to end up right in a utf8 boundary + // (see GH-170 for more info). + // Move back. + while !value.is_char_boundary(start) { + start -= 1; + } result.push_str(&escape_backslashes(&value[start..end], config.after)); result diff --git a/mdast_util_to_markdown/tests/paragraph.rs b/mdast_util_to_markdown/tests/paragraph.rs index b04929d..b880103 100644 --- a/mdast_util_to_markdown/tests/paragraph.rs +++ b/mdast_util_to_markdown/tests/paragraph.rs @@ -104,4 +104,17 @@ fn paragraph() { "a\t \n \tb\n", "should encode spaces around line endings in paragraphs" ); + + assert_eq!( + to(&Node::Paragraph(Paragraph { + children: vec![Node::Text(Text { + value: String::from("я_я"), + position: None + })], + position: None + })) + .unwrap(), + "яяя\n", + "should support escaping around non-ascii" + ); }