script

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package script provides scripting and template elements.

Elements:

Script attributes:

  • Src: External script URL
  • Type: Script type (module, text/javascript)
  • Async: Load asynchronously
  • Defer: Defer execution until DOM ready
  • Crossorigin: CORS settings
  • Integrity: Subresource integrity hash
  • Nomodule: Skip for module-supporting browsers

Canvas attributes:

  • [Width], [Height]: Canvas dimensions

Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element#scripting

Package script provides HTML scripting elements.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Async

func Async() attr.Node

Async sets the async boolean attribute.

func Blocking

func Blocking(v string) attr.Node

Blocking sets the blocking attribute.

func Canvas

func Canvas(attrs ...attr.Node) elem.Scope

Canvas creates a canvas element.

Example
package main

import (
	"github.com/protolambda/chord/core"
	"github.com/protolambda/chord/core/attr"
	"github.com/protolambda/chord/html/script"
)

func main() {
	core.Dump(script.Canvas(attr.ID("game"), attr.KV("width", "800"), attr.KV("height", "600")))
}
Output:
<canvas id="game" width="800" height="600"></canvas>

func Crossorigin

func Crossorigin(v string) attr.Node

Crossorigin sets the crossorigin attribute.

func Defer

func Defer() attr.Node

Defer sets the defer boolean attribute.

func Integrity

func Integrity(v string) attr.Node

Integrity sets the integrity attribute.

func Nomodule

func Nomodule() attr.Node

Nomodule sets the nomodule boolean attribute.

func Noscript

func Noscript(attrs ...attr.Node) elem.Scope

Noscript creates a noscript element.

Example
package main

import (
	"github.com/protolambda/chord/core"
	"github.com/protolambda/chord/html/script"
	"github.com/protolambda/chord/html/text"
)

func main() {
	core.Dump(script.Noscript()(text.Text("JavaScript required")))
}
Output:
<noscript>JavaScript required</noscript>

func Referrerpolicy

func Referrerpolicy(v string) attr.Node

Referrerpolicy sets the referrerpolicy attribute.

func Script

func Script(attrs ...attr.Node) elem.Scope

Script creates a script element.

Example
package main

import (
	"github.com/protolambda/chord/core"
	"github.com/protolambda/chord/html/script"
)

func main() {
	core.Dump(script.Script(script.Src("/app.js")))
}
Output:
<script src="/app.js"></script>
Example (Inline)
package main

import (
	"github.com/protolambda/chord/core"
	"github.com/protolambda/chord/core/elem"
	"github.com/protolambda/chord/html/script"
)

func main() {
	core.Dump(script.Script()(elem.Raw("console.log('hello');")))
}
Output:
<script>console.log('hello');</script>
Example (Module)
package main

import (
	"github.com/protolambda/chord/core"
	"github.com/protolambda/chord/html/script"
)

func main() {
	core.Dump(script.Script(script.Type("module"), script.Src("/mod.js")))
}
Output:
<script type="module" src="/mod.js"></script>

func Src

func Src(v string) attr.Node

Src sets the src attribute.

func Template

func Template(attrs ...attr.Node) elem.Scope

Template creates a template element.

Example
package main

import (
	"github.com/protolambda/chord/core"
	"github.com/protolambda/chord/core/attr"
	"github.com/protolambda/chord/html/script"
	"github.com/protolambda/chord/html/text"
)

func main() {
	core.Dump(script.Template(attr.ID("item-tpl"))(text.Span()(text.Text("Item"))))
}
Output:
<template id="item-tpl"><span>Item</span></template>

func Type

func Type(v string) attr.Node

Type sets the type attribute.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL