Escape a value for YAML
Produce the safely quoted form of the value the user supplies.
Steps
- Inspect the value for YAML special characters, leading/trailing whitespace, and strings YAML
would coerce to another type (
yes,no,null, version-like numbers). - Choose the quoting style: single quotes by default; double quotes when the value contains
single quotes or control characters; a literal block (
|) for multi-line values. - Never emit an unquoted scalar for user-supplied input.
- Show the escaped value and the reason the quoting style was chosen.
Output
The escaped value in a fenced code block, followed by one sentence naming the quoting style and why.