Newline character in metadata to be added to draft

Apologies as javascript is not my language of choice - my searches yielded nothing that helped.

I have some metadata in a configuration draft. I have an action that reads that in and uses it to build a new draft. It all works quite well except…

For some of the metadata it would be nice if it could be used to insert newline characters into the content I am building.

For example, if the metadata was:


and I have read that in and parse that into a javascript variable after removing config label:

var suffix
(suffix is now ‘\n\n’)

And I want to create a new draft:

var stringVar = “This is a test”;
d = Draft.create();
d.content = stringVar + suffix;

the draft is:
This is a test\n\n

Rather than the phrase followed by a blank line.

I am going to build a function to look specifically for the ‘\n’ and build a string using the interpolated “\n” but I am wondering if there is a simpler way?

Regex to the rescue

suffix = suffix.replace(/\n/g, “\n”);

That gets it to work.