@@ -78,9 +78,10 @@ public Optional<String> parseLanguage() throws IOException {
7878
7979 public GeneratedIPythonFile parseNotebook () throws IOException {
8080 String content = inputFile .wrappedFile ().contents ();
81+ boolean isCompressed = content .lines ().count () <= 1 ;
8182 JsonFactory factory = new JsonFactory ();
8283 try (JsonParser jParser = factory .createParser (content )) {
83- return parseCells (jParser ).map (notebookData -> {
84+ return parseCells (jParser , isCompressed ).map (notebookData -> {
8485 // Account for EOF token
8586 JsonLocation location = jParser .currentTokenLocation ();
8687 notebookData .addDefaultLocation (lastPythonLine , location .getLineNr (), location .getColumnNr ());
@@ -90,27 +91,27 @@ public GeneratedIPythonFile parseNotebook() throws IOException {
9091
9192 }
9293
93- private Optional <NotebookParsingData > parseCells (JsonParser parser ) throws IOException {
94+ private Optional <NotebookParsingData > parseCells (JsonParser parser , boolean isCompressed ) throws IOException {
9495 while (!parser .isClosed ()) {
9596 parser .nextToken ();
9697 String fieldName = parser .currentName ();
9798 if ("cells" .equals (fieldName )) {
9899 // consume array start token
99100 parser .nextToken ();
100- Optional <NotebookParsingData > data = parseCellArray (parser );
101+ Optional <NotebookParsingData > data = parseCellArray (parser , isCompressed );
101102 parser .close ();
102103 return data ;
103104 }
104105 }
105106 return Optional .empty ();
106107 }
107108
108- private Optional <NotebookParsingData > parseCellArray (JsonParser jParser ) throws IOException {
109+ private Optional <NotebookParsingData > parseCellArray (JsonParser jParser , boolean isCompressed ) throws IOException {
109110 List <NotebookParsingData > cellsData = new ArrayList <>();
110111
111112 while (jParser .nextToken () != JsonToken .END_ARRAY ) {
112113 if (jParser .currentToken () == JsonToken .START_OBJECT ) {
113- processCodeCell (cellsData , jParser );
114+ processCodeCell (cellsData , jParser , isCompressed );
114115 }
115116 }
116117 Optional <NotebookParsingData > aggregatedNotebookData = cellsData .stream ().reduce (NotebookParsingData ::combine );
@@ -134,7 +135,7 @@ private static boolean processCodeCellType(JsonParser jParser) throws IOExceptio
134135 return false ;
135136 }
136137
137- private void processCodeCell (List <NotebookParsingData > accumulator , JsonParser jParser ) throws IOException {
138+ private void processCodeCell (List <NotebookParsingData > accumulator , JsonParser jParser , boolean isCompressed ) throws IOException {
138139 boolean isCodeCell = false ;
139140 Optional <NotebookParsingData > notebookData = Optional .empty ();
140141 while (jParser .nextToken () != JsonToken .END_OBJECT ) {
@@ -154,7 +155,7 @@ private void processCodeCell(List<NotebookParsingData> accumulator, JsonParser j
154155 }
155156 switch (jParser .currentToken ()) {
156157 case START_ARRAY :
157- notebookData = Optional .of (parseSourceArray (startLine , jParser ));
158+ notebookData = Optional .of (parseSourceArray (startLine , jParser , isCompressed ));
158159 break ;
159160 case VALUE_STRING :
160161 notebookData = Optional .of (parseSourceMultilineString (startLine , jParser ));
@@ -172,7 +173,7 @@ private void processCodeCell(List<NotebookParsingData> accumulator, JsonParser j
172173 }
173174 }
174175
175- private static NotebookParsingData parseSourceArray (int startLine , JsonParser jParser ) throws IOException {
176+ private static NotebookParsingData parseSourceArray (int startLine , JsonParser jParser , boolean isCompressed ) throws IOException {
176177 NotebookParsingData cellData = NotebookParsingData .fromLine (startLine );
177178 JsonLocation tokenLocation = jParser .currentTokenLocation ();
178179 // In case of an empty cell, we don't add an extra line
@@ -181,7 +182,7 @@ private static NotebookParsingData parseSourceArray(int startLine, JsonParser jP
181182 String sourceLine = jParser .getValueAsString ();
182183 var newTokenLocation = jParser .currentTokenLocation ();
183184 var countEscapedChar = countEscapeCharacters (sourceLine , newTokenLocation .getColumnNr ());
184- cellData .addLineToSource (sourceLine , newTokenLocation .getLineNr (), newTokenLocation .getColumnNr (), countEscapedChar );
185+ cellData .addLineToSource (sourceLine , newTokenLocation .getLineNr (), newTokenLocation .getColumnNr (), countEscapedChar , isCompressed );
185186 lastSourceLine = sourceLine ;
186187 tokenLocation = newTokenLocation ;
187188 }
0 commit comments