Skip to content
This repository was archived by the owner on Mar 31, 2022. It is now read-only.

Commit 8470a76

Browse files
authored
(#34) Make the optimizer output a little more useable:
* Hide the optimizer output under a spoiler; * Hide `InterruptException`s from the output; * Add another condition to the end of a spoiler.
1 parent e5b59ae commit 8470a76

File tree

1 file changed

+82
-12
lines changed

1 file changed

+82
-12
lines changed

docs/convert.jl

Lines changed: 82 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ for (index, notebook) in enumerate(notebooks)
121121
# Initialize an empty Markdown lines set
122122
md_lines = Dict{Int, String}()
123123

124+
# A flag showing whether current notebook is about a kernel
125+
about_kernel = false
126+
124127
# Determine the preamble
125128
for preamble in preambles
126129
if name == preamble
@@ -145,6 +148,8 @@ for (index, notebook) in enumerate(notebooks)
145148
# Choose a Markdown lines set
146149
md_lines = md_lines_kernel
147150

151+
about_kernel = true
152+
148153
break
149154

150155
end
@@ -163,48 +168,113 @@ for (index, notebook) in enumerate(notebooks)
163168
# Initialize auxiliary variables
164169
inside_julia_block = false
165170
inside_output_block = false
171+
inside_interrupt_exception = false
166172
last_index = size(lines, 1)
167173

168174
# Initialize the code block counter
169175
code_block = 0
170176

171-
# Put the text output in the text blocks
177+
# Put the text output in the text blocks (and more!)
172178
for (index, line) in enumerate(lines)
173179

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
176187

177188
code_block += 1
178189

179-
# Condition to complete the output block
190+
# Condition of exiting an output block (code block)
180191
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+
182205
inside_output_block = false
206+
183207
end
184208

185209
# Insert a Markdown line if it is defined for the current cell
186210
lines[index] = get(md_lines, code_block, "") * '\n' * lines[index]
187211

212+
inside_interrupt_exception = false
188213
inside_julia_block = true
189214

190-
# Condition of exiting the code block
215+
# Condition of exiting a code block
191216
elseif startswith(line, "```") && inside_julia_block
192217

193218
inside_julia_block = false
194219

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)
196242
elseif inside_output_block && !isempty(line) && !startswith(line, " ")
197243

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+
199256
inside_output_block = false
200257

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
203274

204-
lines[index - 1] = "\n```text\n"
205275
inside_output_block = true
206276

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
208278
elseif inside_output_block && index == last_index
209279

210280
lines[index] = "\n```"

0 commit comments

Comments
 (0)