Double HTML Encoding with Google Apps Script HTMLS

2019-05-12 12:08发布

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'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!

1条回答
冷血范
2楼-- · 2019-05-12 12:26

Use <?!= instead of <?= if you don't want escaping.

查看更多
登录 后发表回答