@@ -121,6 +121,9 @@ for (index, notebook) in enumerate(notebooks)
121
121
# Initialize an empty Markdown lines set
122
122
md_lines = Dict {Int, String} ()
123
123
124
+ # A flag showing whether current notebook is about a kernel
125
+ about_kernel = false
126
+
124
127
# Determine the preamble
125
128
for preamble in preambles
126
129
if name == preamble
@@ -145,6 +148,8 @@ for (index, notebook) in enumerate(notebooks)
145
148
# Choose a Markdown lines set
146
149
md_lines = md_lines_kernel
147
150
151
+ about_kernel = true
152
+
148
153
break
149
154
150
155
end
@@ -163,48 +168,113 @@ for (index, notebook) in enumerate(notebooks)
163
168
# Initialize auxiliary variables
164
169
inside_julia_block = false
165
170
inside_output_block = false
171
+ inside_interrupt_exception = false
166
172
last_index = size (lines, 1 )
167
173
168
174
# Initialize the code block counter
169
175
code_block = 0
170
176
171
- # Put the text output in the text blocks
177
+ # Put the text output in the text blocks (and more!)
172
178
for (index, line) in enumerate (lines)
173
179
174
- # Condition of entering the code block
175
- if startswith (line, " ```julia" ) && ! inside_julia_block
180
+ # Condition of being inside an interrupt exception block
181
+ if inside_interrupt_exception && startswith (line, " " )
182
+
183
+ lines[index] = " "
184
+
185
+ # Condition of entering a code block
186
+ elseif startswith (line, " ```julia" ) && ! inside_julia_block
176
187
177
188
code_block += 1
178
189
179
- # Condition to complete the output block
190
+ # Condition of exiting an output block (code block)
180
191
if inside_output_block
181
- lines[index - 1 ] = " ```\n "
192
+
193
+ # Condition of placing the end of a spoiler (before a block of code)
194
+ if about_kernel && code_block == 4
195
+ lines[index - 1 ] = """
196
+ ```
197
+ ```@raw html
198
+ </details><br>
199
+ ```
200
+ """
201
+ else
202
+ lines[index - 1 ] = " ```\n "
203
+ end
204
+
182
205
inside_output_block = false
206
+
183
207
end
184
208
185
209
# Insert a Markdown line if it is defined for the current cell
186
210
lines[index] = get (md_lines, code_block, " " ) * ' \n ' * lines[index]
187
211
212
+ inside_interrupt_exception = false
188
213
inside_julia_block = true
189
214
190
- # Condition of exiting the code block
215
+ # Condition of exiting a code block
191
216
elseif startswith (line, " ```" ) && inside_julia_block
192
217
193
218
inside_julia_block = false
194
219
195
- # Condition to complete the output block
220
+ # Condition of entering a block of interrupt exception
221
+ elseif ! inside_interrupt_exception && inside_output_block #=
222
+ =# && line == " InterruptException:"
223
+
224
+ # Condition of placing the end of a spoiler (before an interrupt exception)
225
+ if about_kernel && code_block == 4
226
+ lines[index - 1 ] = """
227
+ ```
228
+ ```@raw html
229
+ </details><br>
230
+ ```
231
+ """
232
+ else
233
+ lines[index - 1 ] = " ```\n "
234
+ end
235
+
236
+ lines[index] = " "
237
+
238
+ inside_output_block = false
239
+ inside_interrupt_exception = true
240
+
241
+ # Condition of exiting an output block (Markdown line)
196
242
elseif inside_output_block && ! isempty (line) && ! startswith (line, " " )
197
243
198
- lines[index - 1 ] = " ```\n "
244
+ # Condition of placing the end of a spoiler (before a Markdown line)
245
+ if about_kernel && code_block == 4
246
+ lines[index - 1 ] = """
247
+ ```
248
+ ```@raw html
249
+ </details><br>
250
+ ```
251
+ """
252
+ else
253
+ lines[index - 1 ] = " ```\n "
254
+ end
255
+
199
256
inside_output_block = false
200
257
201
- # Condition for starting the output block
202
- elseif ! inside_output_block && ! inside_julia_block && startswith (line, " " )
258
+ # Condition of entering an output block
259
+ elseif ! inside_output_block && ! inside_julia_block && ! inside_interrupt_exception #=
260
+ =# && startswith (line, " " )
261
+
262
+ # Condition of placing the start of a spoiler
263
+ if about_kernel && code_block == 4
264
+ lines[index - 1 ] = """
265
+ ```@raw html
266
+ <details>
267
+ <summary>Optimizer output</summary>
268
+ ```
269
+ ```text
270
+ """
271
+ else
272
+ lines[index - 1 ] = " \n ```text\n "
273
+ end
203
274
204
- lines[index - 1 ] = " \n ```text\n "
205
275
inside_output_block = true
206
276
207
- # Condition on the last line of the last block of output
277
+ # Condition of getting the last line of the last block of output
208
278
elseif inside_output_block && index == last_index
209
279
210
280
lines[index] = " \n ```"
0 commit comments