Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In the Settings of CSV file format it is already possible to replace newlines in rendered fields.
But with this option you can only replace "real" line feeds (\n). Because in Windows it is normal that a linefeed consists of a Carriage Return plus a Linefeed (\r\n) it would be nice if you could choose what to replace.
Please find attached a patch (against the last dev-version) to enhance the functionality accordingly.
Comment | File | Size | Author |
---|---|---|---|
#15 | linefeeds_as_replacements-1957114-15.patch | 1.22 KB | vasike |
#8 | views_data_export-allow_carriage_return-1957114-8.patch | 6.33 KB | arnested |
Comments
Comment #1
TWD CreditAttribution: TWD commentedHas this been committed to 7.x-3.0-beta6 ?
I am still having this issue.
Comment #2
Steven Jones CreditAttribution: Steven Jones commentedThis needs some tests to make sure that the patch does what it should, and the patch in the OP was also diffed in the wrong direction, i.e. you have to apply the reverse to get it to apply.
Comment #3
nemethf CreditAttribution: nemethf commentedI made a patch based on smitty's one. It replaces all the new line combinations ('\r\n' or '\n' or '\n') by choosing the second option on the style settings. It is needed for us, because text field values in our db are inhomogeneous regarding the new lines. Test cases are included.
Comment #4
nemethf CreditAttribution: nemethf commentedComment #5
arnested CreditAttribution: arnested at Reload commentedYou need change all the strings containing \n, \r\n, and \r to use double quotes instead of single quotes.
Otherwise you'll just replace literal occurrences of \n, \r\n, and \r. That is why the tests also succeed.
Change that and I'll be ready to RTBC :-)
Comment #6
arnested CreditAttribution: arnested at Reload commentedI made the changes mentioned in #5.
Comment #8
arnested CreditAttribution: arnested at Reload commentedOoops. The test case wasn't fixed correctly.
New patch added.
Comment #9
arnested CreditAttribution: arnested at Reload commentedComment #10
nemethf CreditAttribution: nemethf commentedThanks Arne, for pointing to the quotation bug. I tested the corrected patch. Works well with test data.
Comment #11
ikeigenwijs CreditAttribution: ikeigenwijs commentedPatch applied directly.
Works as advertised this was exactly what we needed.
We have mixed environments Windows and Linux so \n and \n\r are used.
Comment #13
Steven Jones CreditAttribution: Steven Jones at ComputerMinds commentedThanks everyone for the patch and the work, fixed in 7.x-3.x
Comment #15
vasikeit seems the replacement doesn't work properly for special characters: as \n
For example there could be both Carriage Return plus Linefeed ("\r\n") and single Linefeed ("\n") that we want to replace with single Linefeed ("\n")
With the current code we'll get the '\n' string instead of single Linefeed ("\n")
Here is patch that could help for this kind of replacements.