package format import ( "strings" "github.com/a-h/templ/internal/prettier" "github.com/a-h/templ/parser/v2" ) const templScriptPlaceholder = "templ_go_expression_7331" // ScriptElement formats a ScriptElement node, replacing Go expressions with placeholders for formatting. // After formatting, it updates the GoCode expressions and their ranges. func ScriptElement(se *parser.ScriptElement, depth int, prettierCommand string) (err error) { // Skip empty script elements, as they don't need formatting. if len(se.Contents) == 0 { return nil } // ScriptElements may contain Go expressions in {{ }} blocks. Prettier has no idea how to handle // that, so we replace them with a placeholder, format the script, and then replace the placeholders // with the original Go expressions. var placeholderContent []parser.ScriptContents var scriptWithPlaceholders strings.Builder for _, part := range se.Contents { if part.Value != nil { scriptWithPlaceholders.WriteString(*part.Value) continue } if part.GoCode != nil { scriptWithPlaceholders.WriteString(templScriptPlaceholder) placeholderContent = append(placeholderContent, part) continue } } //