Skip to content

Commit 5175947

Browse files
committed
Fix text not serializing correctly when having utf8 boundries
1 parent dcf8a63 commit 5175947

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

mdast_util_to_markdown/src/state.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ impl<'a> State<'a> {
242242
results.push(' ');
243243
new_info.before = " ";
244244
} else {
245-
new_info.before = &results[results.len() - 1..];
245+
if let Some(last_char) = results.chars().last() {
246+
new_info.before = &results[results.len() - last_char.len_utf8()..];
247+
}
246248
}
247249
}
248250

mdast_util_to_markdown/tests/roundtrip.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,15 @@ a _\\__ is this emphasis? _\\__"
398398
.unwrap())
399399
.unwrap();
400400
assert_eq!(to(&from(&doc, &Default::default()).unwrap()).unwrap(), doc);
401+
402+
let doc = "𝄞[some](another)";
403+
let tree = markdown::to_mdast(&doc, &markdown::ParseOptions::default()).unwrap();
404+
405+
assert_eq!(
406+
to(&tree).unwrap(),
407+
"𝄞[some](another)\n",
408+
"should support utf8 in boundries when serializing"
409+
);
401410
}
402411

403412
fn remove_pos(node: &mut Node) {

0 commit comments

Comments
 (0)