Skip to content

Commit

Permalink
Fix some Windows newline behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Aug 1, 2020
1 parent 3134eef commit 566706e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/mdman/src/format/md.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl MdFormatter {

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

fn render_options_start(&self) -> &'static str {
Expand Down
3 changes: 3 additions & 0 deletions crates/mdman/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ pub fn convert(
Format::Text => Box::new(format::text::TextFormatter::new(url)),
};
let expanded = hbs::expand(file, &*formatter)?;
// pulldown-cmark can behave a little differently with Windows newlines,
// just normalize it.
let expanded = expanded.replace("\r\n", "\n");
formatter.render(&expanded)
}

Expand Down
2 changes: 2 additions & 0 deletions crates/mdman/tests/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ fn run(name: &str) {
std::fs::write(&expected_path, result).unwrap();
} else {
let expected = std::fs::read_to_string(&expected_path).unwrap();
// Fix if Windows checked out with autocrlf.
let expected = expected.replace("\r\n", "\n");
assert_eq!(expected, result);
}
}
Expand Down

0 comments on commit 566706e

Please sign in to comment.