You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let testYaml = #"""
script:
- |
if [[ some test ]]; then
echo "Hello world!"
fi
"""#
let loaded = try Yams.load(yaml: testYaml) as? [String: Any]
print(loaded as Any)
prints
Optional(["script": ["if [[ some test ]]; then\n echo \"Hello world!\"\nfi"]])
But when I try to encode something with newlines:
let dump = try Yams.dump(object: loaded)
print(dump)
prints
script:
- "if [[ some test ]]; then\n echo \"Hello world!\"\nfi"
instead of using a multiline literal, it instead encodes them as \n. This is confusing, since Yams handles parsing these fine, but is unable to handle encoding them. If you'd like to maintain the current behaviour, I'd suggested adding something like this to Emitter.Options:
enumNewLineHandlingStrategy{
/// Encode newlines in strings as \n
case escapeNewlines
/// Encode newlines in strings with a literal block, ie |
case literal
/// Encode newlines in strings with a foided block, ie >
case folded
}
/// Create `Emitter.Options` with the specified values.
///
/// - parameter canonical: Set if the output should be in the "canonical" format described in the YAML
/// specification.
/// - parameter indent: Set the indentation value.
/// - parameter width: Set the preferred line width. -1 means unlimited.
/// - parameter allowUnicode: Set if unescaped non-ASCII characters are allowed.
/// - parameter lineBreak: Set the preferred line break.
/// - parameter explicitStart: Explicit document start `---`.
/// - parameter explicitEnd: Explicit document end `...`.
/// - parameter version: The `%YAML` directive value or nil.
/// - parameter sortKeys: Set if emitter should sort keys in lexicographic order.
/// - parameter sequenceStyle: Set the style for sequences (arrays / lists)
/// - parameter mappingStyle: Set the style for mappings (dictionaries)
publicinit(canonical:Bool= false, indent:Int=0, width:Int=0, allowUnicode:Bool= false,
lineBreak:Emitter.LineBreak=.ln, version:(major:Int, minor:Int)?=nil,
sortKeys:Bool= false, sequenceStyle:Node.Sequence.Style=.any,
mappingStyle:Node.Mapping.Style=.any, newLineScalarStyle:Node.Scalar.Style=.any){
Parameters list comments could be updated to have newLineScalarStyle info 🙂
This code:
prints
But when I try to encode something with newlines:
prints
instead of using a multiline literal, it instead encodes them as
\n
. This is confusing, since Yams handles parsing these fine, but is unable to handle encoding them. If you'd like to maintain the current behaviour, I'd suggested adding something like this toEmitter.Options
:Here's a reference on these
The text was updated successfully, but these errors were encountered: