Skip to content

fix: preserve whitespace in multiline YAML comments - #45

Merged
IRus merged 4 commits into
Heapy:mainfrom
QrackyDev:main
Oct 25, 2026
Merged

IRus merged 4 commits into
Heapy:mainfrom
QrackyDev:main

Conversation

@QrackyDev

@QrackyDev QrackyDev commented Oct 13, 2026 •

Copy link
Copy Markdown

A newline inside @YamlComment previously left subsequent lines without a # prefix. Split each argument on LF, CRLF, or CR and emit every resulting line as a YAML comment.

Preserve indentation, blank lines, and trailing spaces, including existing annotations that pass one string per line. Literal backslash sequences remain literal text. Whitespace normalization belongs to the caller; the writer does not call trimIndent().

@YamlComment("Example:\n  parent:\n    child: value")
val enabled: Boolean = true
# Example:
#   parent:
#     child: value
enabled: true

Raw multiline strings are supported with their whitespace preserved. Kotlin and the supported target set remain unchanged.

Validation: six focused regression tests cover separate indented arguments, LF/CRLF/CR, blank lines, raw multiline strings, and literal backslashes. The JVM writing suite and Spotless checks pass.

@QrackyDev QrackyDev changed the title Support multiline comments and escape characters fix: support multiline comments and escape characters Oct 13, 2026
@IRus IRus changed the title fix: support multiline comments and escape characters fix: preserve whitespace in multiline YAML comments Oct 25, 2026
@IRus

IRus commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

@QrackyDev thanks, I've just removed trimIndent since it's broking already existing comments:

@YamlComment(
    "Example:",
    "  parent:",
    "    child: value",
)

Before:

# Example:
#   parent:
#     child: value

After:

# Example:
# parent:
# child: value

in Kotlin 2.5.0 this would work just fine:

@YamlComment(
    """
    |Example:
    |  parent:
    |    child: value
    """.trimMargin(),
)
val enabled: Boolean

// yaml:

# Example:
#   parent:
#     child: value
enabled: true

@IRus
IRus merged commit 5eeee73 into Heapy:main Oct 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants