WriteJavaScriptToYAML writes a JavaScript script with proper indentation to a strings.Builder
(yaml *strings.Builder, script string)
| 417 | |
| 418 | // WriteJavaScriptToYAML writes a JavaScript script with proper indentation to a strings.Builder |
| 419 | func WriteJavaScriptToYAML(yaml *strings.Builder, script string) { |
| 420 | // Validate that script is not empty - this helps catch errors where getter functions |
| 421 | // return empty strings after embedded scripts were removed |
| 422 | if strings.TrimSpace(script) == "" { |
| 423 | jsLog.Print("WARNING: Attempted to write empty JavaScript script to YAML") |
| 424 | return |
| 425 | } |
| 426 | |
| 427 | // Remove JavaScript comments first |
| 428 | cleanScript := removeJavaScriptComments(script) |
| 429 | |
| 430 | scriptLines := strings.SplitSeq(cleanScript, "\n") |
| 431 | for line := range scriptLines { |
| 432 | // Skip empty lines when inlining to YAML |
| 433 | if strings.TrimSpace(line) != "" { |
| 434 | fmt.Fprintf(yaml, " %s\n", line) |
| 435 | } |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | // GetLogParserScript returns the JavaScript content for a log parser by name |