Description
openedon Oct 7, 2022
I have noticed that the current TOML.print
seems to exclusively output single-line strings.
This is almost fine, except that multi-line/paragraph strings are also (undesirably) compacted, harming readability.
As an example, I took an extract from the TOML spec.
exampledoc = """
Objectives
TOML aims to be a minimal configuration file format that's easy to read due to
obvious semantics. TOML is designed to map unambiguously to a hash table. TOML
should be easy to parse into data structures in a wide variety of languages.
Spec
- TOML is case-sensitive.
- A TOML file must be a valid UTF-8 encoded Unicode document.
- Whitespace means tab (0x09) or space (0x20).
- Newline means LF (0x0A) or CRLF (0x0D 0x0A).
Comment
A hash symbol marks the rest of the line as a comment, except when inside a
string.
"""
becomes (after a round-trip)
exampledoc = "Objectives\n\nTOML aims to be a minimal configuration file format that's easy to read due to obvious semantics. TOML is designed to map unambiguously to a hash table. TOML should be easy to parse into data structures in a wide variety of languages.\nSpec\n\n- TOML is case-sensitive.\n- A TOML file must be a valid UTF-8 encoded Unicode document.\n- Whitespace means tab (0x09) or space (0x20).\n- Newline means LF (0x0A) or CRLF (0x0D 0x0A).\n\nComment\n\nA hash symbol marks the rest of the line as a comment, except when inside a string.\n"
I'd think a heuristic along the lines of "if the string has multiple newlines, and is more than (some N, ~50?) characters long, use a multi-line string" would be reasonable, and help readability in most cases.