1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Change node linebreak handling to use "\n "

This commit is contained in:
Nick O'Leary 2020-06-22 13:08:35 +01:00
parent e548bf8bc2
commit 581f71911a
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -2220,31 +2220,24 @@ RED.view = (function() {
function convertLineBreakCharacter(str) { function convertLineBreakCharacter(str) {
var result = []; var result = [];
var count = 0; var lines = str.split(/\\n /);
var result_temp = ''; if (lines.length > 1) {
for (var i = 0;i < str.length;i++) { var i=0;
if (str.charAt(i) == '\\') { for (i=0;i<lines.length - 1;i++) {
if (str.charAt(i+1) == '\\') { if (/\\$/.test(lines[i])) {
result_temp += str.charAt(i); result.push(lines[i]+"\\n "+lines[i+1])
i++;
} else if (str.charAt(i+1) == 'n') {
result.push(result_temp.trim());
if (i+1 == str.length-1) {
result.push('');
}
result_temp = '';
count = i+2;
i++; i++;
} else { } else {
result_temp += str.charAt(i); result.push(lines[i])
}
}
if ( i === lines.length - 1) {
result.push(lines[lines.length-1]);
} }
} else { } else {
result_temp += str.charAt(i); result = lines;
}
}
if (count == 0 || count < str.length) {
result.push(result_temp.trim());
} }
result = result.map(function(l) { return l.replace(/\\\\n /g,"\\n ").trim() })
return result; return result;
} }
@ -2544,9 +2537,9 @@ RED.view = (function() {
.attr("class","red-ui-flow-port-tooltip"); .attr("class","red-ui-flow-port-tooltip");
// First check for a user-provided newline - "\\n " // First check for a user-provided newline - "\\n "
var newContent = content.split(/\\n/,1)[0]; var newlineIndex = content.indexOf("\\n ");
if (newContent.length !== content.length) { if (newlineIndex > -1 && content[newlineIndex-1] !== '\\') {
content = newContent+"..."; content = content.substring(0,newlineIndex)+"...";
} }
var lines = content.split("\n"); var lines = content.split("\n");