Skip to content

Commit 4442db6

Browse files
vranaclaude
andcommitted
latte: documented escaping of srcdoc attribute
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d396a6d commit 4442db6

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎latte/cs/html-attributes.texy‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,26 @@ Stejně jako `class` přijímají i atributy `aria-` pole. To se zpracuje jako s
133133
```
134134

135135

136+
HTML dokument v atributu srcdoc .{data-version:3.2.0}
137+
=====================================================
138+
139+
Atribut `srcdoc` elementu `<iframe>` obsahuje celý HTML dokument. Latte proto hodnotu escapuje dvakrát: nejprve jako HTML text a poté jako atribut. Řetězec se v rámu zobrazí jako prostý text a nemůže do něj vložit žádné značky:
140+
141+
```latte
142+
<iframe srcdoc={$text}></iframe>
143+
```
144+
145+
Pokud `$text` obsahuje `<b>Ahoj</b>`, vykreslí se:
146+
147+
```latte
148+
<iframe srcdoc="&amp;lt;b&amp;gt;Ahoj&amp;lt;/b&amp;gt;"></iframe>
149+
```
150+
151+
Chcete-li vložit důvěryhodné HTML, předejte ho jako objekt `Latte\Runtime\Html`. Jeho značky zůstanou zachovány a escapuje se jen jednou, jako atribut, takže stejný obsah se vykreslí jako `srcdoc="&lt;b&gt;Ahoj&lt;/b&gt;"`.
152+
153+
Předchozí verze vkládaly řetězce jako HTML. Takové hodnoty odhalí [migrační varování |develop#Migrační varování], pokud je hodnotou atributu jediný výraz `{...}`.
154+
155+
136156
Typová kontrola
137157
===============
138158

‎latte/en/html-attributes.texy‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,26 @@ Just like `class`, `aria-` attributes also accept an array. It is treated as a s
133133
```
134134

135135

136+
HTML Documents in srcdoc .{data-version:3.2.0}
137+
==============================================
138+
139+
The `srcdoc` attribute of `<iframe>` contains a whole HTML document. Latte therefore escapes a value twice: first as HTML text and then as an attribute. A string is displayed in the frame as plain text and cannot inject any markup:
140+
141+
```latte
142+
<iframe srcdoc={$text}></iframe>
143+
```
144+
145+
If `$text` is `<b>Hi</b>`, it renders:
146+
147+
```latte
148+
<iframe srcdoc="&amp;lt;b&amp;gt;Hi&amp;lt;/b&amp;gt;"></iframe>
149+
```
150+
151+
To insert trusted HTML, pass it as a `Latte\Runtime\Html` object. Its markup is kept and escaped only once, as an attribute, so the same content renders as `srcdoc="&lt;b&gt;Hi&lt;/b&gt;"`.
152+
153+
Previous versions inserted strings as HTML. The [migration warnings |develop#Migration Warnings] point out such values when the entire attribute value is a single `{...}` expression.
154+
155+
136156
Type Checking
137157
=============
138158

0 commit comments

Comments
 (0)