script

package
v0.3.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TagOpen  = []byte("<script")
	TagClose = []byte("</script>")

	AttrSrc            = []byte(" src=\"")
	AttrType           = []byte(" type=\"")
	AttrAsync          = []byte(" async")
	AttrCrossOrigin    = []byte(" crossorigin=\"")
	AttrDefer          = []byte(" defer")
	AttrIntegrity      = []byte(" integrity=\"")
	AttrNoModule       = []byte(" nomodule")
	AttrNonce          = []byte(" nonce=\"")
	AttrReferrerPolicy = []byte(" referrerpolicy=\"")
	AttrBlocking       = []byte(" blocking=\"")
	AttrFetchPriority  = []byte(" fetchpriority=\"")
)

Byte constants for HTML rendering.

Functions

func JSON

func JSON(data string) *element

JSON Creates a script element with JSON data Example: script.JSON("{\"key\": \"value\"}") Renders: <script type="application/json">{"key": "value"}</script>

func JavaScript

func JavaScript(src string) *element

JavaScript Creates a script element explicitly with JavaScript type Example: script.JavaScript("script.js") Renders: <script src="script.js" type="text/javascript"></script>

func Module

func Module(src string) *element

Module Creates a new script element with type="module" for ES6 modules Example: script.Module("app.js") Renders: <script src="app.js" type="module"></script>

func New

func New(nodes ...node.Node) *element

New Creates a new script element without any initial attributes Example: script.New() Renders: <script></script>

func RawText

func RawText(content string) *element

RawText Creates a new script element with raw inline JavaScript. Uses text.RawText which is not HTML-escaped. Preferred for dynamic inline scripts. Example: script.RawText("var x = 1;") Renders: <script>var x = 1;</script>

func RawTextf

func RawTextf(format string, args ...any) *element

RawTextf Creates a new script element with formatted raw inline JavaScript. Uses text.RawTextf which is not HTML-escaped. Preferred for dynamic inline scripts with interpolation. Example: script.RawTextf("var %s = %d;", varName, val) Renders: <script>var x = 42;</script>

func Src added in v0.2.4

func Src(src string) *element

Src Creates a script element that loads an external script file Example: script.Src("/assets/js/app.js") Renders: <script src="/assets/js/app.js"></script>

func Static

func Static(content string) *element

Static Creates a new script element with static inline JavaScript. Uses text.Static which is not HTML-escaped and is JIT-optimisable. Preferred for compile-time constant scripts. Example: script.Static("alert('Hi');") Renders: <script>alert('Hi');</script>

func Text

func Text(content string) *element

Text Creates a new script element with text content. Uses text.Text which HTML-escapes the output. Warning: HTML escaping will break JavaScript syntax. Use RawText or Static for inline scripts. Example: script.Text("console.log('Hello');") Renders: <script>console.log(&#39;Hello&#39;);</script>

func Textf

func Textf(format string, args ...any) *element

Textf Creates a new script element with formatted text content. Uses text.Textf which HTML-escapes the output. Warning: HTML escaping will break JavaScript syntax. Use RawTextf for inline scripts. Example: script.Textf("console.log('%s');", msg) Renders: <script>console.log(&#39;hello&#39;);</script>

Types

type Element

type Element = element

Element is an exported alias for the private element type

Jump to

Keyboard shortcuts

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