FormatJavaScriptForYAML formats a JavaScript script with proper indentation for embedding in YAML
(script string)
| 394 | |
| 395 | // FormatJavaScriptForYAML formats a JavaScript script with proper indentation for embedding in YAML |
| 396 | func FormatJavaScriptForYAML(script string) []string { |
| 397 | if jsLog.Enabled() { |
| 398 | jsLog.Printf("Formatting JavaScript for YAML: %d bytes", len(script)) |
| 399 | } |
| 400 | var formattedLines []string |
| 401 | |
| 402 | // Remove JavaScript comments first |
| 403 | cleanScript := removeJavaScriptComments(script) |
| 404 | |
| 405 | scriptLines := strings.SplitSeq(cleanScript, "\n") |
| 406 | for line := range scriptLines { |
| 407 | // Skip empty lines when inlining to YAML |
| 408 | if strings.TrimSpace(line) != "" { |
| 409 | formattedLines = append(formattedLines, fmt.Sprintf(" %s\n", line)) |
| 410 | } |
| 411 | } |
| 412 | if jsLog.Enabled() { |
| 413 | jsLog.Printf("Formatted %d lines for YAML", len(formattedLines)) |
| 414 | } |
| 415 | return formattedLines |
| 416 | } |
| 417 | |
| 418 | // WriteJavaScriptToYAML writes a JavaScript script with proper indentation to a strings.Builder |
| 419 | func WriteJavaScriptToYAML(yaml *strings.Builder, script string) { |