|
|
|
@ -909,70 +909,14 @@ function formatCellsEnd(io, ionb, cellCounter, singleChoiceContent, singleChoice |
|
|
|
return cellCounter |
|
|
|
return cellCounter |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
function create_notebook(flavor::PlutoFlavor, chunks, config) |
|
|
|
function processNonAdmonitions(item, io) |
|
|
|
ionb = IOBuffer() |
|
|
|
# Handle non-admonition elements |
|
|
|
# Print header |
|
|
|
|
|
|
|
write(ionb, """ |
|
|
|
|
|
|
|
### A Pluto.jl notebook ### |
|
|
|
|
|
|
|
# v0.16.0 |
|
|
|
|
|
|
|
# ╔═╡ a0000000-0000-0000-0000-000000000000 |
|
|
|
|
|
|
|
using $(flavor.use_cm ? "CommonMark, PlutoUI, Test" : "Markdown") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Print cells |
|
|
|
|
|
|
|
uuids = Base.UUID[] |
|
|
|
|
|
|
|
singleChoiceUuids = Base.UUID[] |
|
|
|
|
|
|
|
singleChoiceFolds = Bool[] |
|
|
|
|
|
|
|
singleChoiceContent = String[] |
|
|
|
|
|
|
|
folds = Bool[] |
|
|
|
|
|
|
|
default_fold = Dict{String,Bool}("markdown"=>true, "code"=>false) # toggleable ??? |
|
|
|
|
|
|
|
cellCounter = 1 |
|
|
|
|
|
|
|
for chunk in chunks |
|
|
|
|
|
|
|
io = IOBuffer() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Jupyter style metadata # TODO: factor out, identical to jupyter notebook |
|
|
|
|
|
|
|
chunktype = isa(chunk, MDChunk) ? "markdown" : "code" |
|
|
|
|
|
|
|
fold = default_fold[chunktype] |
|
|
|
|
|
|
|
if !isempty(chunk.lines) && line_is_nbmeta(chunk.lines[1]) |
|
|
|
|
|
|
|
@show chunk.lines |
|
|
|
|
|
|
|
metatype, metadata = parse_nbmeta(chunk.lines[1]) |
|
|
|
|
|
|
|
metatype !== nothing && metatype != chunktype && error("specifying a different cell type is not supported") |
|
|
|
|
|
|
|
popfirst!(chunk.lines) |
|
|
|
|
|
|
|
fold = get(metadata, "fold", fold) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if isa(chunk, MDChunk) |
|
|
|
|
|
|
|
if length(chunk.lines) == 1 |
|
|
|
|
|
|
|
line = escape_string(chunk.lines[1].second, '"') |
|
|
|
|
|
|
|
write(io, "$(flavor.use_cm ? "cm" : "md")\"", line, "\"\n") |
|
|
|
|
|
|
|
elseif containsAdmonition(chunk) |
|
|
|
|
|
|
|
write(io, "$(flavor.use_cm ? "cm" : "md")\"\"\"\n") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
str = chunkToMD(chunk) |
|
|
|
|
|
|
|
helperList = [] |
|
|
|
|
|
|
|
helperTestList = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Content before the Admonition |
|
|
|
|
|
|
|
################################################################ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mdContent = str.content |
|
|
|
|
|
|
|
for item in mdContent |
|
|
|
|
|
|
|
if !isa(item, Markdown.Admonition) |
|
|
|
|
|
|
|
write(io, string(Markdown.MD(item)), '\n') |
|
|
|
write(io, string(Markdown.MD(item)), '\n') |
|
|
|
elseif isa(item, Markdown.Admonition) |
|
|
|
end |
|
|
|
# The Admonition |
|
|
|
|
|
|
|
######################################################## |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
admonition = item |
|
|
|
function processSingleChoice(admonition, depth, io, helperList) |
|
|
|
|
|
|
|
# Handle single-choice processing |
|
|
|
questionName = replace("$(admonition.title)" * "$(replace(string(gensym()), "#" => ""))", r"[^\d\w]+" => "") |
|
|
|
questionName = replace("$(admonition.title)" * "$(replace(string(gensym()), "#" => ""))", r"[^\d\w]+" => "") |
|
|
|
questionCategory = admonition.category |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if questionCategory == "sc" |
|
|
|
|
|
|
|
#################################################### |
|
|
|
|
|
|
|
# Single-Choice Admonition |
|
|
|
|
|
|
|
#################################################### |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
answers = [] |
|
|
|
answers = [] |
|
|
|
questionDict = Dict("correct" => "") |
|
|
|
questionDict = Dict("correct" => "") |
|
|
|
|
|
|
|
|
|
|
|
@ -1011,12 +955,11 @@ function create_notebook(flavor::PlutoFlavor, chunks, config) |
|
|
|
|
|
|
|
|
|
|
|
push!(helperList, radioBind) |
|
|
|
push!(helperList, radioBind) |
|
|
|
push!(helperList, logicBind) |
|
|
|
push!(helperList, logicBind) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
elseif questionCategory == "mc" |
|
|
|
function processMultipleChoice(admonition, depth, io, helperList) |
|
|
|
#################################################### |
|
|
|
# Handle multiple-choice processing |
|
|
|
# Multiple-Choice Admonition |
|
|
|
questionName = replace("$(admonition.title)" * "$(replace(string(gensym()), "#" => ""))", r"[^\d\w]+" => "") |
|
|
|
#################################################### |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
answers = [] |
|
|
|
answers = [] |
|
|
|
questionDict = Dict("correct" => String[]) |
|
|
|
questionDict = Dict("correct" => String[]) |
|
|
|
|
|
|
|
|
|
|
|
@ -1053,12 +996,11 @@ function create_notebook(flavor::PlutoFlavor, chunks, config) |
|
|
|
|
|
|
|
|
|
|
|
push!(helperList, radioBind) |
|
|
|
push!(helperList, radioBind) |
|
|
|
push!(helperList, logicBind) |
|
|
|
push!(helperList, logicBind) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
elseif questionCategory == "freecode" |
|
|
|
function processFreecode(admonition, depth, io, helperList, helperTestList) |
|
|
|
#################################################### |
|
|
|
# Handle freecode processing |
|
|
|
# Freecode Admonition |
|
|
|
questionName = replace("$(admonition.title)" * "$(replace(string(gensym()), "#" => ""))", r"[^\d\w]+" => "") |
|
|
|
#################################################### |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests = [] |
|
|
|
tests = [] |
|
|
|
|
|
|
|
|
|
|
|
testList = filter(x -> isa(x, Markdown.List), admonition.content) |
|
|
|
testList = filter(x -> isa(x, Markdown.List), admonition.content) |
|
|
|
@ -1087,14 +1029,94 @@ function create_notebook(flavor::PlutoFlavor, chunks, config) |
|
|
|
|
|
|
|
|
|
|
|
push!(helperTestList, radioBind) |
|
|
|
push!(helperTestList, radioBind) |
|
|
|
push!(helperList, logicBind) |
|
|
|
push!(helperList, logicBind) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function processNormalAdmonition(admonition, depth, io) |
|
|
|
|
|
|
|
write(io, string(Markdown.MD(admonition)), '\n') |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function processAdmonition(admonition, depth, io, helperList, helperTestList) |
|
|
|
|
|
|
|
category = admonition.category |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if category == "sc" |
|
|
|
|
|
|
|
processSingleChoice(admonition, depth, io, helperList) |
|
|
|
|
|
|
|
elseif category == "mc" |
|
|
|
|
|
|
|
processMultipleChoice(admonition, depth, io, helperList) |
|
|
|
|
|
|
|
elseif category == "freecode" |
|
|
|
|
|
|
|
processFreecode(admonition, depth, io, helperList, helperTestList) |
|
|
|
else |
|
|
|
else |
|
|
|
#################################################### |
|
|
|
processNormalAdmonition(admonition, depth, io) |
|
|
|
# Normal Admonitions |
|
|
|
end |
|
|
|
#################################################### |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
write(io, string(Markdown.MD(item)), '\n') |
|
|
|
function processContent(mdContent, io) |
|
|
|
|
|
|
|
for item in mdContent |
|
|
|
|
|
|
|
if isa(item, Markdown.Admonition) |
|
|
|
|
|
|
|
processAdmonition(item, 0, io) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
processNonAdmonitions(item, io) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function create_notebook(flavor::PlutoFlavor, chunks, config) |
|
|
|
|
|
|
|
ionb = IOBuffer() |
|
|
|
|
|
|
|
# Print header |
|
|
|
|
|
|
|
write(ionb, """ |
|
|
|
|
|
|
|
### A Pluto.jl notebook ### |
|
|
|
|
|
|
|
# v0.16.0 |
|
|
|
|
|
|
|
# ╔═╡ a0000000-0000-0000-0000-000000000000 |
|
|
|
|
|
|
|
using $(flavor.use_cm ? "CommonMark, PlutoUI, Test" : "Markdown") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Print cells |
|
|
|
|
|
|
|
uuids = Base.UUID[] |
|
|
|
|
|
|
|
singleChoiceUuids = Base.UUID[] |
|
|
|
|
|
|
|
singleChoiceFolds = Bool[] |
|
|
|
|
|
|
|
singleChoiceContent = String[] |
|
|
|
|
|
|
|
folds = Bool[] |
|
|
|
|
|
|
|
default_fold = Dict{String,Bool}("markdown"=>true, "code"=>false) # toggleable ??? |
|
|
|
|
|
|
|
cellCounter = 1 |
|
|
|
|
|
|
|
for chunk in chunks |
|
|
|
|
|
|
|
io = IOBuffer() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Jupyter style metadata # TODO: factor out, identical to jupyter notebook |
|
|
|
|
|
|
|
chunktype = isa(chunk, MDChunk) ? "markdown" : "code" |
|
|
|
|
|
|
|
fold = default_fold[chunktype] |
|
|
|
|
|
|
|
if !isempty(chunk.lines) && line_is_nbmeta(chunk.lines[1]) |
|
|
|
|
|
|
|
@show chunk.lines |
|
|
|
|
|
|
|
metatype, metadata = parse_nbmeta(chunk.lines[1]) |
|
|
|
|
|
|
|
metatype !== nothing && metatype != chunktype && error("specifying a different cell type is not supported") |
|
|
|
|
|
|
|
popfirst!(chunk.lines) |
|
|
|
|
|
|
|
fold = get(metadata, "fold", fold) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if isa(chunk, MDChunk) |
|
|
|
|
|
|
|
if length(chunk.lines) == 1 |
|
|
|
|
|
|
|
line = escape_string(chunk.lines[1].second, '"') |
|
|
|
|
|
|
|
write(io, "$(flavor.use_cm ? "cm" : "md")\"", line, "\"\n") |
|
|
|
|
|
|
|
elseif containsAdmonition(chunk) |
|
|
|
|
|
|
|
write(io, "$(flavor.use_cm ? "cm" : "md")\"\"\"\n") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
str = chunkToMD(chunk) |
|
|
|
|
|
|
|
helperList = [] |
|
|
|
|
|
|
|
helperTestList = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mdContent = str.content |
|
|
|
|
|
|
|
for item in mdContent |
|
|
|
|
|
|
|
if !isa(item, Markdown.Admonition) |
|
|
|
|
|
|
|
write(io, string(Markdown.MD(item)), '\n') |
|
|
|
|
|
|
|
elseif isa(item, Markdown.Admonition) |
|
|
|
|
|
|
|
# The Admonition |
|
|
|
|
|
|
|
######################################################## |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
admonition = item |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
questionCategory = admonition.category |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
processAdmonition(admonition, 0, io, helperList, helperTestList) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@ -1132,6 +1154,7 @@ function create_notebook(flavor::PlutoFlavor, chunks, config) |
|
|
|
content = read(io, String) |
|
|
|
content = read(io, String) |
|
|
|
# Compute number of expressions in the code block and perhaps wrap in begin/end |
|
|
|
# Compute number of expressions in the code block and perhaps wrap in begin/end |
|
|
|
nexprs, idx = 0, 1 |
|
|
|
nexprs, idx = 0, 1 |
|
|
|
|
|
|
|
ex = nothing |
|
|
|
while true |
|
|
|
while true |
|
|
|
ex, idx = Meta.parse(content, idx) |
|
|
|
ex, idx = Meta.parse(content, idx) |
|
|
|
ex === nothing && break |
|
|
|
ex === nothing && break |
|
|
|
|