本文介绍了使用Google Apps Script HTMLService进行双HTML编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google Apps脚本Html服务呈现HTML页面。

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

 使用<?!= 而不是<?= ,如果您不想转义。


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&#39;s  
view source is: "text-align: center\"> Miss McCleod&amp;#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&amp;#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编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 10:29