Skip to content

Commit e1b5505

Browse files
committed
fix Quarto callout blocks
1 parent 7f14daa commit e1b5505

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

assets/scripts/notebooks/notebooks.jl

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,37 @@ function JSON.lower(nb::Notebook)
5151
)
5252
end
5353

54+
"""
55+
fix_callouts(md_content::AbstractString)::String
56+
57+
Convert Quarto callouts in `md_content` to blockquotes.
58+
"""
59+
function fix_callouts(md_content::AbstractString)::String
60+
# Quarto callouts look like, for example, `::: {.callout-note}`
61+
# There isn't a good Jupyter equivalent, so we'll just use blockquotes.
62+
# https://github.com/quarto-dev/quarto-cli/issues/1167
63+
callout_regex = r"^:::\s*\{\.callout-\w+\}.*$"
64+
callout_end_regex = r"^:::\s*$"
65+
new_lines = String[]
66+
in_callout = false
67+
for line in split(md_content, '\n')
68+
if in_callout
69+
if occursin(callout_end_regex, line)
70+
in_callout = false
71+
else
72+
push!(new_lines, "> " * line)
73+
end
74+
else
75+
if occursin(callout_regex, line)
76+
in_callout = true
77+
else
78+
push!(new_lines, line)
79+
end
80+
end
81+
end
82+
return join(new_lines, '\n')
83+
end
84+
5485
"""
5586
parse_cells(qmd_path::String)::Notebook
5687
@@ -78,7 +109,7 @@ function parse_cells(qmd_path::String)::Notebook
78109
for (i, md_content) in enumerate(markdown_cell_contents)
79110
md_content = strip(md_content)
80111
if !isempty(md_content)
81-
push!(cells, MarkdownCell(md_content))
112+
push!(cells, MarkdownCell(fix_callouts(md_content)))
82113
end
83114
if i <= length(code_cell_contents)
84115
match = code_cell_contents[i]

0 commit comments

Comments
 (0)