Skip to content

Commit 2514d89

Browse files
refactor: don't generate a type attribute for <script> elements, update associated docs (#1053)
1 parent 6ea47ff commit 2514d89

File tree

26 files changed

+61
-61
lines changed

26 files changed

+61
-61
lines changed

docs/docs/03-syntax-and-usage/03-attributes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ templ Button(text string) {
225225
```
226226

227227
```html title="Output"
228-
<script type="text/javascript">
228+
<script>
229229
function __templ_withParameters_1056(a, b, c){console.log(a, b, c);}function __templ_withoutParameters_6bbf(){alert("hello");}
230230
</script>
231231
<button onclick="__templ_withParameters_1056("test","Say hello",123)" onmouseover="__templ_withoutParameters_6bbf()" type="button">

docs/docs/03-syntax-and-usage/12-script-templates.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Use standard `<script>` tags, and standard HTML attributes to run JavaScript on
66

77
```templ
88
templ body() {
9-
<script type="text/javascript">
9+
<script>
1010
function handleClick(event) {
1111
alert(event + ' clicked');
1212
}
@@ -49,7 +49,7 @@ HTML element `on*` attributes pass an event object to the function. To pass the
4949
:::
5050

5151
```templ title="input.templ"
52-
<script type="text/javascript">
52+
<script>
5353
function clickHandler(event, message) {
5454
alert(message);
5555
event.preventDefault();
@@ -61,7 +61,7 @@ HTML element `on*` attributes pass an event object to the function. To pass the
6161
The output would be:
6262

6363
```html title="output.html"
64-
<script type="text/javascript">
64+
<script>
6565
function clickHandler(event, message) {
6666
alert(message);
6767
event.preventDefault();
@@ -87,7 +87,7 @@ templ InitializeClientSideScripts(data CustomType) {
8787
This will output a `<script>` tag that calls the `functionToCall` function with the `Name` and `Age` properties of the `data` object.
8888

8989
```html title="output.html"
90-
<script type="text/javascript">
90+
<script>
9191
functionToCall("John", 42);
9292
</script>
9393
```
@@ -169,15 +169,15 @@ var helloHandle = templ.NewOnceHandle()
169169
templ hello(label, name string) {
170170
// This script is only rendered once per HTTP request.
171171
@helloHandle.Once() {
172-
<script type="text/javascript">
172+
<script>
173173
function hello(name) {
174174
alert('Hello, ' + name + '!');
175175
}
176176
</script>
177177
}
178178
<div>
179179
<input type="button" value={ label } data-name={ name }/>
180-
<script type="text/javascript">
180+
<script>
181181
// To prevent the variables from leaking into the global scope,
182182
// this script is wrapped in an IIFE (Immediately Invoked Function Expression).
183183
(() => {
@@ -213,7 +213,7 @@ var surrealHandle = templ.NewOnceHandle()
213213
214214
templ hello(label, name string) {
215215
@helloHandle.Once() {
216-
<script type="text/javascript">
216+
<script>
217217
function hello(name) {
218218
alert('Hello, ' + name + '!');
219219
}
@@ -224,7 +224,7 @@ templ hello(label, name string) {
224224
}
225225
<div>
226226
<input type="button" value={ label } data-name={ name }/>
227-
<script type="text/javascript">
227+
<script>
228228
// me("-") returns the previous sibling element.
229229
me("-").addEventListener('click', function() {
230230
let name = this.getAttribute('data-name');
@@ -492,9 +492,9 @@ After building and running the executable, running `curl http://localhost:8080/`
492492
```html title="Output"
493493
<html>
494494
<body>
495-
<script type="text/javascript">function __templ_printToConsole_5a85(content){console.log(content)}</script>
496-
<script type="text/javascript">__templ_printToConsole_5a85("2023-11-11 01:01:40.983381358 +0000 UTC")</script>
497-
<script type="text/javascript">__templ_printToConsole_5a85("Again: 2023-11-11 01:01:40.983381358 +0000 UTC")</script>
495+
<script>function __templ_printToConsole_5a85(content){console.log(content)}</script>
496+
<script>__templ_printToConsole_5a85("2023-11-11 01:01:40.983381358 +0000 UTC")</script>
497+
<script>__templ_printToConsole_5a85("Again: 2023-11-11 01:01:40.983381358 +0000 UTC")</script>
498498
</body>
499499
</html>
500500
```

docs/docs/03-syntax-and-usage/17-using-react-with-templ.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ import "fmt"
188188
189189
templ Hello(name string) {
190190
<div data-name={ name }>
191-
<script type="text/javascript">
191+
<script>
192192
bundle.renderHello(document.currentScript.closest('div'));
193193
</script>
194194
</div>
@@ -243,19 +243,19 @@ The HTML that's rendered is:
243243
<script src="static/index.js"></script>
244244

245245
<div data-name="Alice">
246-
<script type="text/javascript">
246+
<script>
247247
// Place the React component into the parent div.
248248
bundle.renderHello(document.currentScript.closest('div'));
249249
</script>
250250
</div>
251251
<div data-name="Bob">
252-
<script type="text/javascript">
252+
<script>
253253
// Place the React component into the parent div.
254254
bundle.renderHello(document.currentScript.closest('div'));
255255
</script>
256256
</div>
257257
<div data-name="Charlie">
258-
<script type="text/javascript">
258+
<script>
259259
// Place the React component into the parent div.
260260
bundle.renderHello(document.currentScript.closest('div'));
261261
</script>

docs/docs/03-syntax-and-usage/18-render-once.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var helloHandle = templ.NewOnceHandle()
1919
2020
templ hello(label, name string) {
2121
@helloHandle.Once() {
22-
<script type="text/javascript">
22+
<script>
2323
function hello(name) {
2424
alert('Hello, ' + name + '!');
2525
}
@@ -35,7 +35,7 @@ templ page() {
3535
```
3636

3737
```html title="Output"
38-
<script type="text/javascript">
38+
<script>
3939
function hello(name) {
4040
alert('Hello, ' + name + '!');
4141
}

docs/docs/10-security/01-injection-attacks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ templ is designed to prevent user-provided data from being used to inject vulner
66

77
```html
88
templ Example() {
9-
<script type="text/javascript">
9+
<script>
1010
function showAlert() {
1111
alert("hello");
1212
}

docs/docs/10-security/02-content-security-policy.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ func main() {
7575
```
7676

7777
```html title="Output"
78-
<script type="text/javascript" nonce="randomly generated nonce">
78+
<script nonce="randomly generated nonce">
7979
function __templ_onLoad_5a85() {
8080
alert("Hello, world!")
8181
}
8282
</script>
83-
<script type="text/javascript" nonce="randomly generated nonce">
83+
<script nonce="randomly generated nonce">
8484
__templ_onLoad_5a85()
8585
</script>
8686
```

examples/integration-react/components.templ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package main
22

33
templ Hello(name string) {
44
<div data-name={ name }>
5-
<script type="text/javascript">
5+
<script>
66
// Place the React component into the parent div.
77
bundle.renderHello(document.currentScript.closest('div'));
88
</script>

examples/integration-react/components_templ.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generator/generator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ func (g *generator) writeElement(indentLevel int, n parser.Element) (err error)
973973
if err = g.writeElementCSS(indentLevel, attrs); err != nil {
974974
return err
975975
}
976-
// <script type="text/javascript"></script>
976+
// <script></script>
977977
if err = g.writeElementScript(indentLevel, attrs); err != nil {
978978
return err
979979
}
@@ -1356,7 +1356,7 @@ func (g *generator) writeRawElement(indentLevel int, n parser.RawElement) (err e
13561356
return err
13571357
}
13581358
} else {
1359-
// <script type="text/javascript"></script>
1359+
// <script></script>
13601360
if err = g.writeElementScript(indentLevel, n.Attributes); err != nil {
13611361
return err
13621362
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<button onClick="anythingILike('blah')">
22
Click me
33
</button>
4-
<script type="text/javascript">
4+
<script>
55
// Arbitrary JS code
66
</script>

0 commit comments

Comments
 (0)