Skip to content

Fix text not serializing correctly when having utf8 boundaries #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mdast_util_to_markdown/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ impl<'a> State<'a> {
results.push(' ');
new_info.before = " ";
} else {
new_info.before = &results[results.len() - 1..];
if let Some(last_char) = results.chars().last() {
new_info.before = &results[results.len() - last_char.len_utf8()..];
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions mdast_util_to_markdown/tests/roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,15 @@ a _\\__ is this emphasis? _\\__"
.unwrap())
.unwrap();
assert_eq!(to(&from(&doc, &Default::default()).unwrap()).unwrap(), doc);

let doc = "𝄞[some](another)";
let tree = markdown::to_mdast(&doc, &markdown::ParseOptions::default()).unwrap();

assert_eq!(
to(&tree).unwrap(),
"𝄞[some](another)\n",
"should support utf8 in boundries when serializing"
);
Comment on lines +408 to +409
Copy link
Preview

Copilot AI Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: please change 'boundries' to 'boundaries' for clarity.

Suggested change
"should support utf8 in boundries when serializing"
);
"should support utf8 in boundaries when serializing"

Copilot uses AI. Check for mistakes.

}

fn remove_pos(node: &mut Node) {
Expand Down