2013-12-18 27 views
0

我有一個簡單的使用html服務的應用程序腳本,我需要:僞選擇器之後。如何使用Google Apps腳本html服務顯示數據屬性?after?

熬煮問題一行代碼,我有

<style> 
test:after { 
    content: attr(data-hidden); 
    display: inline-block; 
    font-weight: bold; 
} 
</style> 

<test data-hidden="Now you don't">Now you see me </test> 

每的jsfiddle,預期產出將是「現在你看到我現在你不」,但我只得到「現在你看到我「

如果我刪除:我得到現在你看到我,如預期。

FWIW我使用.setSandboxMode(HtmlService.SandboxMode.NATIVE)

誰能告訴我什麼,我做錯了什麼?

回答

1

content: attr()行被caja編譯器剝離。嘗試使用Caja Playground上的代碼片段,然後檢查呈現結果,這應該更好地表示HTML服務器在從Google Apps腳本服務時如何進行消毒,而不是在jsfiddle中獲得的結果。

下面是呈現:

<caja-v-html> 
    <caja-v-head> 
    <style> 
     .CajaGadget2___ caja-v-test:after{ 
     display:inline-block; 
     font-weight:bold;} 
    </style> 
    </caja-v-head> 
    <caja-v-body> 
    <caja-v-test data-caja-data-hidden="Now you don't">Now you see me </caja-v-test> 
    </caja-v-body> 
</caja-v-html> 

<test>標籤的data-hidden屬性生存,但沒有content屬性的風格包含它。這可能是因爲attr()聲明似乎是一個攻擊媒介。 (example

如果我們用一個恆定content再試一次,它生存哄騙:

<caja-v-html> 
    <caja-v-head> 
    <style> 
     .CajaGadget2___ caja-v-test:after{ 
     content:"waffles";   <<<<<< 
     display:inline-block; 
     font-weight:bold;} 
    </style> 
    </caja-v-head> 
    <caja-v-body> 
    <caja-v-test data-caja-data-hidden="Now you don't">Now you see me </caja-v-test> 
    </caja-v-body> 
</caja-v-html> 

由於消毒的,你不會是能夠使attr()這種方式工作。您可以在Caja Issue Tracker上輸入問題。

+0

確實,attr被拒絕了[code review](https://codereview.appspot.com/7308092/diff/6002/src/com/google/caja/lang/css/css-extensions- defs.json#newcode169) 「拒絕ATTR(),因爲它規避了Domado屬性值 的虛擬化」, kpreid2 2013年2月13日二十點26分59秒 這在原則上是在某些情況下,靜態可確定的(雖然它會需要來自選擇器的上下文 )。雖然我們同意我們現在不需要它。 ihab.awad 2013/02/13 22:20:30完成。 這是一個遺憾,因爲我想 – jetpax

+0

使用它來實現一個響應表使用(http://codepen.io/geoffyuen/pen/FCBEg) – jetpax

相關問題