From 2571c52a974778fb75a813b8136892466f6b0b6c Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 8 Dec 2025 17:47:57 +0100 Subject: [PATCH] Don't discard empty lines in @BeginCode blocks --- gap/DocumentationTree.gd | 1 + gap/DocumentationTree.gi | 25 +++++++++++++++++++++ gap/Parser.gi | 4 ++-- tst/worksheets/general.expected/_Chunks.xml | 2 ++ tst/worksheets/general.sheet/worksheet.g | 1 + 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/gap/DocumentationTree.gd b/gap/DocumentationTree.gd index e91718cc..15298fcb 100644 --- a/gap/DocumentationTree.gd +++ b/gap/DocumentationTree.gd @@ -49,6 +49,7 @@ DeclareOperation( "SectionInTree", [ IsTreeForDocumentation, IsString, IsString DeclareOperation( "SubsectionInTree", [ IsTreeForDocumentation, IsString, IsString, IsString ] ); DeclareOperation( "DocumentationExample", [ IsTreeForDocumentation ] ); DeclareOperation( "DocumentationChunk", [ IsTreeForDocumentation, IsString ] ); +DeclareOperation( "DocumentationChunkContent", [ IsObject ] ); DeclareOperation( "DocumentationManItem", [ IsTreeForDocumentation ] ); DeclareOperation( "SetManItemToDescription", [ IsTreeForDocumentationNode ] ); DeclareOperation( "SetManItemToReturnValue", [ IsTreeForDocumentationNode ] ); diff --git a/gap/DocumentationTree.gi b/gap/DocumentationTree.gi index 1edb3411..141ad8f8 100644 --- a/gap/DocumentationTree.gi +++ b/gap/DocumentationTree.gi @@ -104,6 +104,13 @@ BindGlobal( "TheTypeOfDocumentationTreeExampleNodes", NewType( TheFamilyOfDocumentationTreeNodes, IsTreeForDocumentationExampleNodeRep ) ); + +## DeclareRepresentation +DeclareRepresentation( "IsTreeForDocumentationChunkContentNodeRep", IsTreeForDocumentationNodeRep, [ ] ); +BindGlobal( "TheTypeOfDocumentationTreeChunkContentNodes", NewType( TheFamilyOfDocumentationTreeNodes, IsTreeForDocumentationChunkContentNodeRep ) ); + + + ################################### ## ## Tools @@ -230,6 +237,16 @@ InstallMethod( DocumentationChunk, [ IsTreeForDocumentation, IsString ], return node; end ); +## +InstallMethod( DocumentationChunkContent, [ IsObject ], + function( content ) + local node; + + node := rec( content := content ); + ObjectifyWithAttributes( node, TheTypeOfDocumentationTreeChunkContentNodes ); + return node; +end ); + ## InstallMethod( DocumentationManItem, [ IsTreeForDocumentation ], function( tree ) @@ -588,6 +605,14 @@ InstallMethod( WriteDocumentation, [ IsTreeForDocumentationChunkNodeRep, IsStrea WriteDocumentation( Concatenation( "<#Include Label=\"", Label( node ), "\">" ), filestream, level_value ); end ); +InstallMethod( WriteDocumentation, [ IsTreeForDocumentationChunkContentNodeRep, IsStream, IsInt ], + function( node, filestream, level_value ) + local s; + for s in node!.content do + AppendTo( filestream, s ); + od; +end ); + ## InstallMethod( WriteDocumentation, [ IsTreeForDocumentationExampleNodeRep, IsStream, IsInt ], function( node, filestream, level_value ) diff --git a/gap/Parser.gi b/gap/Parser.gi index d8020b53..297e7bb9 100644 --- a/gap/Parser.gi +++ b/gap/Parser.gi @@ -415,7 +415,7 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles, local code, temp_curr_line, comment_pos, before_comment; code := [ " fail then @@ -713,7 +713,7 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles, local label_name, tmp_system; label_name := ReplacedString( current_command[ 2 ], " ", "_" ); tmp_system := DocumentationChunk( tree, label_name ); - Append( tmp_system!.content, read_code() ); + Add( tmp_system!.content, DocumentationChunkContent( read_code() ) ); end, @Code := ~.@BeginCode, @InsertCode := ~.@InsertChunk, diff --git a/tst/worksheets/general.expected/_Chunks.xml b/tst/worksheets/general.expected/_Chunks.xml index a39b48ec..ac174517 100644 --- a/tst/worksheets/general.expected/_Chunks.xml +++ b/tst/worksheets/general.expected/_Chunks.xml @@ -7,6 +7,7 @@ + <#/GAPDoc> diff --git a/tst/worksheets/general.sheet/worksheet.g b/tst/worksheets/general.sheet/worksheet.g index 1b912c30..1b307e4f 100644 --- a/tst/worksheets/general.sheet/worksheet.g +++ b/tst/worksheets/general.sheet/worksheet.g @@ -179,6 +179,7 @@ DeclareOperation( "ThirdOperation", [ IsGroup, IsInt ] ); #! @BeginCode MyCode #! Hello, world. x := 1 + 1; + if x = 2 then Print("1 + 1 = 2 holds, all is good\n"); else