-
I want to have the following output: schedule:
- cron: '* /10 * * *'
- cron: '5 4 * * *' This is just a
You can also check this out in the pkl-playground: But unfortunately the output is the following: schedule:
- cron: '*/10 * * *'
- cron: 5 4 * * * Notice the missing single quotes in the second It seems that the While this might be (I'm not 100% sure with that 😁 ) technically correct, I still want to force wrapping it into quotes. Test cases:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
YAML can be formatted in many different ways. I don’t think YamlRenderer gives users full control over the chosen syntax. |
Beta Was this translation helpful? Give feedback.
-
Render directives are an escape hatch to get the renderer to do what you want. Here's an example: this combines a render directive with an output converter to turn all strings into JSON strings, which is still valid YAML (YAML accepts JSON strings): cron = "* * * * *"
local jsonRenderer = new JsonRenderer {}
output {
renderer = new YamlRenderer {
converters {
[String] = (it) -> new RenderDirective { text = " " + jsonRenderer.renderValue(it) }
}
}
} This produces: cron: "* * * * *" It'll be more work to produce strings with single quotes. If your goal is to have consistent looking strings, I'd just stick with double quotes here.
This is just a style issue; you can trust Pkl to produce the right thing here. |
Beta Was this translation helpful? Give feedback.
Render directives are an escape hatch to get the renderer to do what you want.
Here's an example: this combines a render directive with an output converter to turn all strings into JSON strings, which is still valid YAML (YAML accepts JSON strings):
This produces:
It'll be more work to produce strings with single quotes. If your goal is to have consistent looking strings, I'd just stick with double quotes here.