使用Google Apps Script HTMLService进行双HTML编码 [英] Double HTML Encoding with Google Apps Script HTMLService
问题描述
我使用Google Apps脚本Html服务呈现HTML页面。
问题是HTML实体显示出来而不是预期的特殊字符。例如:
McCleod小姐向McCleod小姐的
视图源提交的内容是:text-align :center \> Miss McCleod' s
渲染与
正常工作
< code> < =&tune.tuneName GT?; < /代码>
但不包含:
< h1 style =text-align:center;><?= tune.tuneName?> < / H1>
其中tune.tuneName是从缓存中提取的对象的成员变量。该对象从谷歌电子表格中填充,Utilities.jsonStringify()和Utilities.jsonParse()用于放入缓存或从缓存中取出。
HTML模板脚本如下所示。
< h1风格= 文本对齐:中心; >< = tune.tuneName>有< / H1>
< code> < =&tune.tuneName GT?; < /代码>
< div style =text-align:center;>
<? var imageUrl = getUrlForAttachmentFileName(tune.musicNotesImageFileName)?>
< img src =<?= imageUrl?> ALT = < =&tune.tuneName GT;?对齐= 中心 >
< / div>
以下代码用于实例化页面。
tuneRec = findTuneById(tuneId);
var printHtmlTemplate = HtmlService.createTemplateFromFile('PrintPage');
printHtmlTemplate.tune = tuneRec;
return printHtmlTemplate.evaluate();
McCleod小姐表示双重编码正在发生。
有关如何解决上述问题的任何想法都将不胜感激。
谢谢!
<?!=
而不是<?=
,如果您不想转义。 I am using the Google Apps Script Html Service to render an HTML page.
The problem is that the HTML Entity gets displayed and not the intended special character. For example:
Miss McCleod's renders to Miss McCleod's
view source is: "text-align: center\"> Miss McCleod&#39;s
Rendering works correctly with
<code> <?=tune.tuneName?> </code>
but not with:
<h1 style="text-align:center;"><?=tune.tuneName?> </h1>
where tune.tuneName is a member variable of an object that has been pulled from the Cache. The object was populated from a google spreadsheet and Utilities.jsonStringify() and Utilities.jsonParse() were used when putting and getting to/from cache.
The HTML templates script is shown below.
<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>
The following code is used to instantiate the page.
tuneRec = findTuneById(tuneId);
var printHtmlTemplate = HtmlService.createTemplateFromFile('PrintPage');
printHtmlTemplate.tune = tuneRec;
return printHtmlTemplate.evaluate();
Miss McCleod&#39;s implies that double encoding is taking place.
Any ideas on how to solve for the above would be greatly appreciated.
Thanks!
Use <?!=
instead of <?=
if you don't want escaping.
这篇关于使用Google Apps Script HTMLService进行双HTML编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!