Skip to content

Commit

Permalink
Use os.eol for line endings
Browse files Browse the repository at this point in the history
When running in node, use os.eol to choose line endings - windows will use \r\n, linux will use \n.

Fixes #260
  • Loading branch information
bitwiseman committed Oct 11, 2013
1 parent d0d79c9 commit 5af378a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion js/lib/beautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,10 @@


sweet_code = output_lines[0].text.join('');
var os = (os || {});
var eol = os['eol'] || '\n';
for (var line_index = 1; line_index < output_lines.length; line_index++) {
sweet_code += '\n' + output_lines[line_index].text.join('');
sweet_code += eol + output_lines[line_index].text.join('');
}
sweet_code = sweet_code.replace(/[\r\n ]+$/, '');
return sweet_code;
Expand Down
7 changes: 6 additions & 1 deletion js/test/beautify-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify)
{

var os = (os || {});
var eol = os['eol'] || '\n';
var opts = {
indent_size: 4,
indent_char: ' ',
Expand Down Expand Up @@ -32,6 +33,10 @@ function run_beautifier_tests(test_obj, Urlencoded, js_beautify, html_beautify)
function test_fragment(input, expected)
{
expected = expected || input;
if(eol !== '\n') {
expected = expected.replace('\r\n','\n');
expected = expected.replace('\n',eol);
}
sanitytest.expect(input, expected);
// if the expected is different from input, run it again
// expected output should be unchanged when run twice.
Expand Down

0 comments on commit 5af378a

Please sign in to comment.