Skip to content

Comments on document level are not loaded if there are no collection in document #4

@ReseTkin

Description

@ReseTkin

yaml example:
'# comment' + sLineBreak +
'name: John Doe' + sLineBreak +
'age: 30'

after loading this document and writing it back - comment is gone

As far as I can see in the following code, this is intended behavior:
`
procedure TYAMLParser.AssignPendingCommentsToCollection(const collection : IYAMLCollection);
var
index : integer;
begin
// Skip assignment if this is the document-level root collection
// Document-level comments should go to the first content structure, not the root container
if FIsDocumentLevel and (collection.Parent = nil) then
Exit;

if FPendingComments.Count > 0 then
begin
for index := 0 to FPendingComments.Count - 1 do
collection.AddComment(FPendingComments[index]);
FPendingComments.Clear;
FIsDocumentLevel := False; // No longer at document level once we've assigned comments
end;
end;
But at the same time I can can create a new document and write:
doc.AsMapping.AddComment('comment');
`
In this case comment will appear at first line after writeToString.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions