【问题标题】:How to insert a new paragraph in a javascript string?如何在 javascript 字符串中插入新段落?
【发布时间】:2013-11-08 02:02:42
【问题描述】:

我正在使用一个脚本来替换 Google 文档模板中的字符串。如果我使用\n 命令,我可以在模板中得到一个新行。

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."

我得到这样的东西:

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

但我想添加的不是新字符串,而是新段落(根据模板设置):

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

有什么办法吗?

【问题讨论】:

    标签: javascript string google-apps-script google-docs


    【解决方案1】:

    您不能从段落内容中创建段落,请在脚本中使用appendParagraph 方法,方法是在脚本本身中分割您的字符串。

    【讨论】:

      【解决方案2】:
          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>"
      

      如果你有你想要段落的字符串部分,这将起作用。如果没有,可以将字符串中的/n替换为&lt;/p&gt;&lt;p&gt;

      【讨论】:

      • 这不是 HTML...请重新考虑您的回答。
      • 这是关于显示段落和 HTML 是其中一种方式。
      • 这一切都发生在 Google 文档中。 Google 文档在其内容中不使用 HTML,而是使用纯文本...这就是为什么在原始帖子中使用 /n 来换行而不是
      • 不是一个漂亮的方法,但你可以用 Jquery 将 /n s 更改为
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-14
      • 2013-05-23
      相关资源
      最近更新 更多