diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-10-13 18:13:08 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-10-13 18:13:08 +0200 |
commit | ef77260efa1122cba42eb97dcadb771ba354276a (patch) | |
tree | 1a4cb084f3ffc710304ab3768bcd3fa988669302 | |
parent | e0ca78397ea34cde06ab8257a8481afc812d344f (diff) | |
download | markdown-rs-ef77260efa1122cba42eb97dcadb771ba354276a.tar.gz markdown-rs-ef77260efa1122cba42eb97dcadb771ba354276a.tar.bz2 markdown-rs-ef77260efa1122cba42eb97dcadb771ba354276a.zip |
Fix cr, crlf in code (fenced) for mdast
-rw-r--r-- | src/to_mdast.rs | 6 | ||||
-rw-r--r-- | tests/code_fenced.rs | 28 |
2 files changed, 31 insertions, 3 deletions
diff --git a/src/to_mdast.rs b/src/to_mdast.rs index fe5bd82..39f6bc5 100644 --- a/src/to_mdast.rs +++ b/src/to_mdast.rs @@ -1721,11 +1721,11 @@ fn trim_eol(value: String, at_start: bool, at_end: bool) -> String { if at_end && end > start { if bytes[end - 1] == b'\n' { end -= 1; - } else if bytes[end - 1] == b'\r' { - end -= 1; - if end > start && bytes[end - 1] == b'\n' { + if end > start && bytes[end - 1] == b'\r' { end -= 1; } + } else if bytes[end - 1] == b'\r' { + end -= 1; } } diff --git a/tests/code_fenced.rs b/tests/code_fenced.rs index c064179..e544ade 100644 --- a/tests/code_fenced.rs +++ b/tests/code_fenced.rs @@ -311,5 +311,33 @@ fn code_fenced() -> Result<(), String> { "should support code (fenced) w/o closing fence in mdast" ); + assert_eq!( + to_mdast("```\rasd\r```", &ParseOptions::default())?, + Node::Root(Root { + children: vec![Node::Code(Code { + lang: None, + meta: None, + value: "asd".into(), + position: Some(Position::new(1, 1, 0, 3, 4, 11)) + })], + position: Some(Position::new(1, 1, 0, 3, 4, 11)) + }), + "should support code (fenced) w/o CR line endings" + ); + + assert_eq!( + to_mdast("```\r\nasd\r\n```", &ParseOptions::default())?, + Node::Root(Root { + children: vec![Node::Code(Code { + lang: None, + meta: None, + value: "asd".into(), + position: Some(Position::new(1, 1, 0, 3, 4, 13)) + })], + position: Some(Position::new(1, 1, 0, 3, 4, 13)) + }), + "should support code (fenced) w/o CR+LF line endings" + ); + Ok(()) } |