namestringthird
", ""] {
+fn empty_inline_elements_between_code_do_not_join_or_invent_text() {
+ for empty in [
+ "",
+ "",
+ "",
+ "",
+ "name{empty}string");
for preformatted in [false, true] {
let result = markdown(&source, preformatted);
@@ -172,6 +180,82 @@ fn empty_code_between_values_does_not_join_or_invent_code_text() {
}
}
+#[test]
+fn code_remains_distinct_when_surrounding_styles_coalesce() {
+ for tag in ["em", "strong", "del"] {
+ let source = format!("<{tag}>name{tag}><{tag}>string{tag}>");
+ for preformatted in [false, true] {
+ let result = markdown(&source, preformatted);
+ assert_eq!(
+ rendered_html(&result),
+ format!("<{tag}>namestring{tag}>
name string",
+ "`name` `string`",
+ ),
+ (
+ "name string",
+ "`name`\u{a0}`string`",
+ ),
+ (
+ "nameandstring",
+ "`name`*and*`string`",
+ ),
+ (
+ "namestring",
+ "*`name`*`string`",
+ ),
+ (
+ "namestring",
+ "`name`*`string`*",
+ ),
+ (
+ "namestring",
+ "`name`[](/a)`string`",
+ ),
+ (
+ "namestring",
+ "`name``string`",
+ ),
+ (
+ "namestring",
+ "`name` \n`string`",
+ ),
+ (
+ "namestring",
+ "`name`\n\n`string`",
+ ),
+ (
+ "abxc",
+ "`a`\n\n> `b`\n\nx`c`",
+ ),
+ ] {
+ for preformatted in [false, true] {
+ assert_eq!(
+ markdown(source, preformatted),
+ expected,
+ "{source}, preformatted={preformatted}"
+ );
+ }
+ }
+ for source in [
+ "name string",
+ "name string",
+ "name string",
+ ] {
+ assert_eq!(markdown(source, false), "`name` `string`", "{source}");
+ }
+}
+
#[test]
fn neighboring_code_values_keep_their_text_and_node_boundaries() {
for (source, preformatted, expected) in [
@@ -195,6 +279,16 @@ fn neighboring_code_values_keep_their_text_and_node_boundaries() {
true,
"firstsecond
first*[x]|<&>`thirdfourth",
+ false,
+ "first*[x]|<&>`thirdfourth
word a b ",
+ true,
+ "word a b
a`b`",
- "reason": "Adjacent code elements retain their semantic boundary without an invented space. Inline HTML preserves the first boundary because adjacent Markdown code spans would merge. Turndown joins their delimiters into one code span whose text contains two extra backticks."
+ "markdown": "`a`b",
+ "reason": "Adjacent code elements retain their semantic boundary without an invented space. Inline HTML preserves the second code element when it immediately follows an emitted Markdown code span. Turndown joins their delimiters into one code span whose text contains two extra backticks."
},
"extra_code_nested_format": {
"markdown": "`ab`",