Skip to content

Commit 566706e

Browse files
committed
Fix some Windows newline behavior.
1 parent 3134eef commit 566706e

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

crates/mdman/src/format/md.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl MdFormatter {
2828

2929
impl super::Formatter for MdFormatter {
3030
fn render(&self, input: &str) -> Result<String, Error> {
31-
Ok(input.to_string())
31+
Ok(input.replace("\r\n", "\n"))
3232
}
3333

3434
fn render_options_start(&self) -> &'static str {

crates/mdman/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ pub fn convert(
5454
Format::Text => Box::new(format::text::TextFormatter::new(url)),
5555
};
5656
let expanded = hbs::expand(file, &*formatter)?;
57+
// pulldown-cmark can behave a little differently with Windows newlines,
58+
// just normalize it.
59+
let expanded = expanded.replace("\r\n", "\n");
5760
formatter.render(&expanded)
5861
}
5962

crates/mdman/tests/compare.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ fn run(name: &str) {
2929
std::fs::write(&expected_path, result).unwrap();
3030
} else {
3131
let expected = std::fs::read_to_string(&expected_path).unwrap();
32+
// Fix if Windows checked out with autocrlf.
33+
let expected = expected.replace("\r\n", "\n");
3234
assert_eq!(expected, result);
3335
}
3436
}

0 commit comments

Comments
 (0)