Skip to content

Commit 5aee079

Browse files
authored
Don't discard empty lines in @BeginCode blocks (#292)
1 parent 4bc560c commit 5aee079

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

gap/DocumentationTree.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ DeclareOperation( "SectionInTree", [ IsTreeForDocumentation, IsString, IsString
4949
DeclareOperation( "SubsectionInTree", [ IsTreeForDocumentation, IsString, IsString, IsString ] );
5050
DeclareOperation( "DocumentationExample", [ IsTreeForDocumentation ] );
5151
DeclareOperation( "DocumentationChunk", [ IsTreeForDocumentation, IsString ] );
52+
DeclareOperation( "DocumentationChunkContent", [ IsObject ] );
5253
DeclareOperation( "DocumentationManItem", [ IsTreeForDocumentation ] );
5354
DeclareOperation( "SetManItemToDescription", [ IsTreeForDocumentationNode ] );
5455
DeclareOperation( "SetManItemToReturnValue", [ IsTreeForDocumentationNode ] );

gap/DocumentationTree.gi

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ BindGlobal( "TheTypeOfDocumentationTreeExampleNodes",
104104
NewType( TheFamilyOfDocumentationTreeNodes,
105105
IsTreeForDocumentationExampleNodeRep ) );
106106

107+
108+
## DeclareRepresentation
109+
DeclareRepresentation( "IsTreeForDocumentationChunkContentNodeRep", IsTreeForDocumentationNodeRep, [ ] );
110+
BindGlobal( "TheTypeOfDocumentationTreeChunkContentNodes", NewType( TheFamilyOfDocumentationTreeNodes, IsTreeForDocumentationChunkContentNodeRep ) );
111+
112+
113+
107114
###################################
108115
##
109116
## Tools
@@ -230,6 +237,16 @@ InstallMethod( DocumentationChunk, [ IsTreeForDocumentation, IsString ],
230237
return node;
231238
end );
232239

240+
##
241+
InstallMethod( DocumentationChunkContent, [ IsObject ],
242+
function( content )
243+
local node;
244+
245+
node := rec( content := content );
246+
ObjectifyWithAttributes( node, TheTypeOfDocumentationTreeChunkContentNodes );
247+
return node;
248+
end );
249+
233250
##
234251
InstallMethod( DocumentationManItem, [ IsTreeForDocumentation ],
235252
function( tree )
@@ -588,6 +605,14 @@ InstallMethod( WriteDocumentation, [ IsTreeForDocumentationChunkNodeRep, IsStrea
588605
WriteDocumentation( Concatenation( "<#Include Label=\"", Label( node ), "\">" ), filestream, level_value );
589606
end );
590607

608+
InstallMethod( WriteDocumentation, [ IsTreeForDocumentationChunkContentNodeRep, IsStream, IsInt ],
609+
function( node, filestream, level_value )
610+
local s;
611+
for s in node!.content do
612+
AppendTo( filestream, s );
613+
od;
614+
end );
615+
591616
##
592617
InstallMethod( WriteDocumentation, [ IsTreeForDocumentationExampleNodeRep, IsStream, IsInt ],
593618
function( node, filestream, level_value )

gap/Parser.gi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles,
415415
local code, temp_curr_line, comment_pos, before_comment;
416416
code := [ "<Listing Type=\"Code\"><![CDATA[\n" ];
417417
while true do
418-
temp_curr_line := Chomp( ReadLineWithLineCount( filestream ) );
418+
temp_curr_line := ReadLineWithLineCount( filestream );
419419
if plain_text_mode = false then
420420
comment_pos := PositionSublist( temp_curr_line, "#!" );
421421
if comment_pos <> fail then
@@ -713,7 +713,7 @@ InstallGlobalFunction( AutoDoc_Parser_ReadFiles,
713713
local label_name, tmp_system;
714714
label_name := ReplacedString( current_command[ 2 ], " ", "_" );
715715
tmp_system := DocumentationChunk( tree, label_name );
716-
Append( tmp_system!.content, read_code() );
716+
Add( tmp_system!.content, DocumentationChunkContent( read_code() ) );
717717
end,
718718
@Code := ~.@BeginCode,
719719
@InsertCode := ~.@InsertChunk,

tst/worksheets/general.expected/_Chunks.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
<Listing Type="Code"><![CDATA[
88
Hello, world.
99
x := 1 + 1;
10+
1011
if x = 2 then
1112
Print("1 + 1 = 2 holds, all is good\n");
1213
else
1314
Error("1+1 <> 2");
1415
fi;
1516
]]></Listing>
1617

18+
1719
<#/GAPDoc>

tst/worksheets/general.sheet/worksheet.g

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ DeclareOperation( "ThirdOperation", [ IsGroup, IsInt ] );
179179
#! @BeginCode MyCode
180180
#! Hello, world.
181181
x := 1 + 1;
182+
182183
if x = 2 then
183184
Print("1 + 1 = 2 holds, all is good\n");
184185
else

0 commit comments

Comments
 (0)