Skip to content

Commit 75a29cb

Browse files
committed
Output correct line endings for Windows
1 parent 71385c4 commit 75a29cb

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/formatting.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
use crate::{Document, FormattedLine, LineType};
22

3+
#[cfg(not(windows))]
4+
const LINEBREAK: &str = "\n";
5+
#[cfg(windows)]
6+
const LINEBREAK: &str = "\r\n";
7+
38
#[derive(Debug, Eq, PartialEq)]
49
enum Action {
510
Start,
@@ -75,11 +80,11 @@ pub fn format_to_string(document: &Document) -> String {
7580

7681
for block in document.blocks.iter() {
7782
if last_action == Action::InsertBodyText {
78-
formatted += "\n";
83+
formatted += LINEBREAK;
7984
}
8085

8186
formatted += &format!(
82-
"{indenting}{header}\n\n",
87+
"{indenting}{header}{LINEBREAK}{LINEBREAK}",
8388
indenting = " ".repeat(block.header.num_indent()),
8489
header = block.header.contents
8590
);
@@ -95,12 +100,12 @@ pub fn format_to_string(document: &Document) -> String {
95100
}
96101

97102
last_action = if formatted_line.is_empty() {
98-
formatted += "\n";
103+
formatted += LINEBREAK;
99104

100105
Action::InsertBlankLine
101106
} else {
102107
formatted += &format!(
103-
"{indenting}{line}\n",
108+
"{indenting}{line}{LINEBREAK}",
104109
indenting = " ".repeat(formatted_line.num_indent()),
105110
line = formatted_line.contents
106111
);

0 commit comments

Comments
 (0)