Skip to content

Commit add76bd

Browse files
wooormbnchi
andcommitted
to_markdown: fix crash on non-ascii around phrasing
Closes GH-169. Closes GH-170. Co-authored-by: bnchi <[email protected]>
1 parent 9987d15 commit add76bd

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

mdast_util_to_markdown/src/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl<'a> State<'a> {
242242
results.push(' ');
243243
new_info.before = " ";
244244
} else {
245-
new_info.before = &results[results.len() - 1..];
245+
new_info.before = &results;
246246
}
247247
}
248248

mdast_util_to_markdown/tests/emphasis.rs

+45-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use markdown::mdast::{Emphasis, Node, Text};
1+
use markdown::mdast::{Emphasis, Node, Paragraph, Text};
22
use mdast_util_to_markdown::{
33
to_markdown as to, to_markdown_with_options as to_md_with_opts, Options,
44
};
@@ -47,4 +47,48 @@ fn emphasis() {
4747
"_a_\n",
4848
"should support an emphasis w/ underscores when `emphasis: \"_\"`"
4949
);
50+
51+
assert_eq!(
52+
to(&Node::Paragraph(Paragraph {
53+
children: vec![
54+
Node::Text(Text {
55+
value: String::from("𝄞"),
56+
position: None
57+
}),
58+
Node::Emphasis(Emphasis {
59+
children: vec![Node::Text(Text {
60+
value: String::from("a"),
61+
position: None,
62+
})],
63+
position: None
64+
})
65+
],
66+
position: None
67+
}))
68+
.unwrap(),
69+
"𝄞*a*\n",
70+
"should support non-ascii before emphasis"
71+
);
72+
73+
assert_eq!(
74+
to(&Node::Paragraph(Paragraph {
75+
children: vec![
76+
Node::Emphasis(Emphasis {
77+
children: vec![Node::Text(Text {
78+
value: String::from("a"),
79+
position: None,
80+
})],
81+
position: None
82+
}),
83+
Node::Text(Text {
84+
value: String::from("𝄞"),
85+
position: None
86+
}),
87+
],
88+
position: None
89+
}))
90+
.unwrap(),
91+
"*a*𝄞\n",
92+
"should support non-ascii after emphasis"
93+
);
5094
}

0 commit comments

Comments
 (0)