windows newline? #13

Closed
arthurblake opened this Issue Jan 30, 2014 · 3 comments

Projects

None yet

3 participants

@arthurblake

Would be nice if newline was \r\n on windows so that the resultant xml created was readable with notepad and other basic windows editors/cmd line. Even nicer would be the ability to specify what to use for newline in the options

examples:

var winXml = require('xml')(myXmlJsonTemplate, {indent: '\t', newline:'\r\n'});
var macXml = require('xml')(myXmlJsonTemplate, {indent: '\t', newline:'\n'});

If no newline specified, '\r\n' would be used as default newline if process.platform === 'win32' otherwise '\n'.

Some might consider this request nitpicky or even counterproductive (as the xml generated would be slightly different depending on platform) and I can see that point of view. But on the other hand it would be super handy for quick viewing on windows.

I'll be happy to implement it and submit it as a pull request if you don't want to make the changes; but I didn't want to waste time on it if the idea would be rejected outright. Let me know. Thanks!

halfdan commented Mar 10, 2014

@arthurblake I usually hate people that reply to such well written requests with "use a better editor", but this is what I have to do in this case :-( There are many editors for Windows that can properly handle \n line breaks. Notepad, by all means, is a mess and shouldn't be your default editor on that platform.

One implication of changing the behaviour on Windows would be that tests could fail depending on the platform.

Owner
dylang commented Mar 10, 2014

Thanks for the suggestion @arthurblake. I agree with @halfdan, the web world has practically standardized on \n, and nearly every Windows app supports it, with Notepad being an obvious exception.

Would replacing the hardcoded \n with os.EOL be a fair compromise?

http://nodejs.org/api/os.html#os_os_eol

If so, can you make a pull request?

That's fair, guys. In this case I was generating xml on windows servers where installing non-standard or special editors is not allowed. I needed to be able to open a configuration xml quickly and notepad was the only editor i had access to. Since the XML I was dealing with in this case was very small, I simply used String.replace to replace \n with \r\n and moved along. Thanks for hearing me out, anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment