0

I'm experimenting with using a Form to create a new announcement on our Google Sites page. The form asks for the title and body of the post. The form is also linked to a spreadsheet. In the form a can be input and will display in the spreadsheet. The console log in the script also shows the paragraph break.

The Sites API seems to strip out the and replace it with a space. For example, what was supposed to be 2 paragraphs, each with one sentence, becomes two sentences in the announcement. How do I get the paragraph break to display in the new announcement created in this script? Any help would be much appreciated. Thank you in advance.

var posted = "POSTED";

for (var i = 0; i < data.length -1; ++i) { 

var timeStamp = data[i][0];  
var name = data[i][1];       
var title = data[i][2];
var body = data[i][3];
var status = data[i][4];

Logger.log(title);
Logger.log(body);
Logger.log(status);

if (status != posted) { 

  var url = 'myintranetsite.com'
  var page = SitesApp.getPageByUrl(url)

  // Got this code from another post, script won't fail in event of duplicate titles
  var announcements = page.getAnnouncements({ 
                                         includeDrafts: false,
                                         includeDeleted: false,
                                         search: title });

  if (announcements.length > 0) {
  title += ' (' + announcements.length + ')'; 

  var newPost = page.createAnnouncement(title, body);
4

2 回答 2

1

是的,原来这是一个关于段落标记和替换特殊字符的问题。谢谢!

这是用于替换表单响应中的新行字符
并插入 para 标记的代码。

var newBody = body.replace(/\n/g, '<br />');   // replaces new line with <br /> 

var htmlBody = "<p>";
htmlBody += newBody;
htmlBody += "<p />";

var newPost = page.createAnnouncement(title, htmlBody);
于 2013-11-20T14:58:39.690 回答
0

我假设有关“段落”标记的问题。

正文应该是 HTML https://developers.google.com/apps-script/reference/sites/page#createAnnouncement(String,String)

我怀疑你想做一个查找和替换。

或者只是将 HTML 放入表单中。例如添加:

 "<p>" 
于 2013-11-16T11:10:28.143 回答