1414import org .jetbrains .annotations .NotNull ;
1515import org .jetbrains .annotations .Nullable ;
1616
17+ import java .util .List ;
1718import java .util .Set ;
1819
1920public class PlantUmlCodeBlockParser extends AbstractBlockParser {
@@ -50,7 +51,7 @@ public BlockContinue tryContinue(ParserState state) {
5051 if (blockData != null ) {
5152 this .blockNode .setEndMarker (blockData .endMarker );
5253 this .blockData .finished = true ;
53- return BlockContinue .atIndex ( state . getIndex () );
54+ return BlockContinue .finished ( );
5455 } else {
5556 // this case should never happen since we made a look-ahead before
5657 this .blockNode .unlink ();
@@ -79,7 +80,10 @@ public void closeBlock(ParserState state) {
7980
8081 if (start != null && end != null
8182 && start .length () > 1 && end .length () > 1 ) {
82- blockNode .setChars (this .blockData .contents );
83+ // Remove first line break from the contents, i.e. after @startuml
84+ List <BasedSequence > lines = this .blockData .contents .splitListEOL ();
85+ blockNode .setContent (lines .subList (1 , lines .size ()));
86+ blockNode .setCharsFromContent ();
8387 }
8488 }
8589 }
@@ -133,8 +137,9 @@ public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockPar
133137 for (BasedSequence currentLine : remainingLines ) {
134138 BlockData result = tryReadingEndMarker (currentLine , blockData );
135139 if (result != null ) {
140+ // go on reading code block in the next line, i.e. first line after e.g. @startuml
136141 return BlockStart .of (new PlantUmlCodeBlockParser (blockData ))
137- .atColumn (state .getColumn ());
142+ .atColumn (state .getLineEndIndex ());
138143 }
139144 }
140145 }
@@ -149,8 +154,7 @@ private static BlockData tryReadingStartMarker(BasedSequence currentLine) {
149154 if (currentLine .startsWith (marker .getStart ())) {
150155 BasedSequence remainder = currentLine .subSequence (marker .getStart ().length ());
151156 if (remainder .isBlank ()) {
152- return new BlockData (marker , currentLine .getStartOffset (),
153- currentLine .subSequence (0 , marker .getStart ().length ()));
157+ return new BlockData (marker , currentLine .subSequence (0 , marker .getStart ().length ()));
154158 }
155159 }
156160 }
@@ -161,7 +165,6 @@ private static BlockData tryReadingEndMarker(BasedSequence currentLine, BlockDat
161165 if (currentLine .startsWith (blockData .marker .getEnd ())) {
162166 BasedSequence remainder = currentLine .subSequence (blockData .marker .getEnd ().length ());
163167 if (remainder .isBlank ()) {
164- blockData .endOffset = currentLine .getEndOffset ();
165168 blockData .endMarker = currentLine .subSequence (0 , blockData .marker .getEnd ().length ());
166169 return blockData ;
167170 }
@@ -171,17 +174,14 @@ private static BlockData tryReadingEndMarker(BasedSequence currentLine, BlockDat
171174
172175 private static class BlockData {
173176 final PlantUmlBlockMarker marker ;
174- int startOffset ;
175- int endOffset ;
176177 BasedSequence startMarker ;
177178 BasedSequence endMarker ;
178179 BasedSequence contents ;
179180
180181 boolean finished = false ;
181182
182- BlockData (PlantUmlBlockMarker marker , int startOffset , BasedSequence startMarker ) {
183+ BlockData (PlantUmlBlockMarker marker , BasedSequence startMarker ) {
183184 this .marker = marker ;
184- this .startOffset = startOffset ;
185185 this .startMarker = startMarker ;
186186 }
187187 }
0 commit comments