does lineSeperator config argument actually work?

I have an issue where I’m using CodeMirror to collect a copy/pasted html document from my user. These documents nearly always are terminated with a “\n” character.

Recently I noticed that my database of stored documents had a LOT of documents with “\r\n” within them. I ultimately traced this down to CodeMirror, after which I discovered the lineSeperator option. I assumed this would immediately fix my problem - but it appears to be doing exactly nothing.

My thinking is that I’m just not understanding how to use the option based on the docs. There is no example here, so I must be wrong about how to use it.

Can someone please comment if the below seems correct?

var editorConfig = {
mode: {
name: ‘xml’,
htmlMode: true,
alignCDATA: true
},
lineNumbers: true,
autofocus: true,
lineWrapping: true,
styleActiveLine: true,
lineSeparator: “\n”
};

The key obviously being the very last attribute there?

Another thing I considered was that the argument for CodeMirror may only be related to the parsing and display of a document being opened, and that the way I’m actually getting the data from CodeMirror could be faulty. Since someone is obviously going to ask me about that, I have the following:

$(’.form-basic’).submit(function() {
editor.save();
});

The general idea was just to save back whatever I had to the textarea, after which I’d be good.

I also tried:

$(’.form-basic’).submit(function() {
$(’#code’).val(editor.getValue());
});

My only other thought is that all of the above is correct, but anytime that you use a textarea you implicitly are dealing with a \r\n, but that seems so so strange to me being from a unix background.

Any and all help appreciated, thanks in advance!

Textareas will normalize line endings, so yes, going through .save() to get the value is probably not what you want.

Yeah, that is the issue. I traced down the cause of the problem right to the W3C spec for textareas:
http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4

Basically all data that is submitted using a textarea will use CRLF. You can submit the data using anything but a textarea to avoid the problem, or just fix it up server side.