craftApprentice
craftApprentice

Reputation: 2777

How to insert a new paragraph in a javascript string?

I'm using a script that replace strings in a Google Docs template. If I use the \n command, I can get a new line in the template.

sample = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. \n Lorem Ipsum is simply dummy text of the printing and typesetting industry."

I get something like this:

      Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum is simply dummy text of the printing and typesetting industry.

But I'd like to add not a new string, but a new paragraph (according to the template settings):

      Lorem Ipsum is simply dummy text of the printing and typesetting industry.
      Lorem Ipsum is simply dummy text of the printing and typesetting industry.

There's some way to do that?

Upvotes: 2

Views: 10542

Answers (2)

Kuzgun
Kuzgun

Reputation: 4737

    sample = "<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.
 </p><p> Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>"

This will work if you have the string part you want to have paragraph. If not, you can replace /n with </p><p> in the string

Upvotes: 0

Serge insas
Serge insas

Reputation: 46802

You cannot create paragraph from within the paragraph's content, use the appendParagraph method in your script by slicing your string in the script itself.

Upvotes: 1

Related Questions