google-apps-script - 使用 Google Apps 脚本 HTMLService 进行双重 HTML 编码

标签 google-apps-script

我正在使用 Google Apps Script Html 服务来呈现 HTML 页面。

问题是显示的是 HTML 实体,而不是预期的特殊字符。例如:

Miss McCleod's renders to Miss McCleod's  
view source is: "text-align: center\"> Miss McCleod's 

渲染工作正常

<code> <?=tune.tuneName?> </code>

但不包括:

<h1 style="text-align:center;"><?=tune.tuneName?> </h1> 

其中tune.tuneName 是从Cache 中拉取的对象的成员变量。该对象是从谷歌电子表格中填充的,并且在放入和获取缓存时使用了 Utilities.jsonStringify() 和 Utilities.jsonParse()。

HTML 模板脚本如下所示。

<h1 style="text-align:center;"><?=tune.tuneName?> </h1> 
<code> <?=tune.tuneName?> </code>

<div style="text-align:center;">    
  <? var imageUrl = getUrlForAttachmentFileName(tune.musicNotesImageFileName) ?>
  <img src="<?=imageUrl?>" alt="<?=tune.tuneName?>" align="center">
</div>


以下代码用于实例化页面。

tuneRec = findTuneById(tuneId);  
var printHtmlTemplate = HtmlService.createTemplateFromFile('PrintPage');
printHtmlTemplate.tune = tuneRec;
return printHtmlTemplate.evaluate();



Miss McCleod&amp;#39;s implies that double encoding is taking place.

如果有任何关于如何解决上述问题的想法,我们将不胜感激。

谢谢!

最佳答案

使用 <?!=而不是 <?=如果你不想逃跑。

关于google-apps-script - 使用 Google Apps 脚本 HTMLService 进行双重 HTML 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13218538/

相关文章:

javascript - 不工作 : Code to send email reminder based on date

javascript - 在新的 Date() 中指定 Olson ID

security - Google Apps 脚本附加源代码/安全性

javascript - 用于在一张纸上对多个表格进行实时排序的 Google Sheets 脚本

google-apps-script - 从 Google Apps 脚本自定义函数读取和写入单元格公式

google-apps-script - 替换文档中的字符串并撤消

Javascript 和 Gmail 相当于 Applescript 和 Apple Mail

google-apps-script - 如何使用 Google Apps Script 在文档中添加页码

html - 在 Google Sheet 中使用 D3.js 可搜索可折叠树

google-apps-script - 脚本经过身份验证会保留多长时间?