Quote from
Gaev on January 10, 2019, 5:02 pm
@luishp:
Yes, I ended up doing something similar ...
SetVar [htmlText] ""
BeginJS
//fetch [plainText]
var plainTextJS = $App.plainText;
//alert(plainTextJS);
//replace all occurences
var htmlTextJS = plainTextJS.replace(/\r\n/g, "<br/>");
//alert(htmlTextJS);
//store result in [htmlText]
$App.htmlText = htmlTextJS;
EndJS
... which takes the content of variable [plainText] (including CR and LF characters) and returns the equivalent html (i.e. <br/>) in variable [htmlText]
Note that ...
a) you can use \r\n to define CR and LF codes
b) the javascript .replace method only replaces the first matching occurrence by default; so you have to use the regex notation to replace all occurences.
@luishp:
Yes, I ended up doing something similar ...
SetVar [htmlText] ""
BeginJS
//fetch [plainText]
var plainTextJS = $App.plainText;
//alert(plainTextJS);
//replace all occurences
var htmlTextJS = plainTextJS.replace(/\r\n/g, "<br/>");
//alert(htmlTextJS);
//store result in [htmlText]
$App.htmlText = htmlTextJS;
EndJS
... which takes the content of variable [plainText] (including CR and LF characters) and returns the equivalent html (i.e. <br/>) in variable [htmlText]
Note that ...
a) you can use \r\n to define CR and LF codes
b) the javascript .replace method only replaces the first matching occurrence by default; so you have to use the regex notation to replace all occurences.
luishp has reacted to this post.