cue-lang / docs-and-content

A place to discuss, plan, and track documentation on cuelang.org
5 stars 1 forks source link

docs/tour/types/stringlit: prose explaining multi-line string whitespace is technically incorrect #174

Open jpluscplusm opened 1 month ago

jpluscplusm commented 1 month ago

What page were you looking at?

https://cuelang.org/docs/tour/types/stringlit/

What version of the site were you looking at?

https://github.com/cue-lang/cuelang.org/commit/fccf4804ae4fabee1fa1f566cd2cca37daa80ab0

What did you do?

I tried to rely on this phrase when writing a multi-line string that contains blank lines:

Any whitespace before the closing quotes must also prefix the lines between the quotes, because it is removed from all lines.

What did you expect?

I expected that blank lines inside a multi-line string would require the string's standard whitespace prefix.

What did you see instead?

The prefix is not required when the intent is to encode a blank line:

exec cue export foo.cue
cmp stdout out
-- foo.cue --
x: """
    The next line is totally blank.

    The next line is blank, but the CUE has a tab prefix

    This is the last line.
    """
-- out --
{
    "x": "The next line is totally blank.\n\nThe next line is blank, but the CUE has a tab prefix\n\nThis is the last line."
}

(This example doesn't make it clear via the web view, but the copy button does generate the correct underlying txtar that demonstrates the corner case)

jpluscplusm commented 1 month ago

The spec's language makes this clear:

The whitespace before a closing triple quote must appear before any non-empty line after the opening quote and will be removed from each of these lines in the string literal.