|
|
|
@ -125,27 +125,6 @@ function parse(content; allow_continued = true) |
|
|
|
return chunks |
|
|
|
return chunks |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
text = """ |
|
|
|
|
|
|
|
# This is not inside the admonition |
|
|
|
|
|
|
|
# !!! danger "Question" |
|
|
|
|
|
|
|
# This is the question |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# 1. `] install ForwardDiff` |
|
|
|
|
|
|
|
# 2. `add ForwardDiff` |
|
|
|
|
|
|
|
# 3. `] add ForwardDiff.jl` |
|
|
|
|
|
|
|
# 4. `] add ForwardDiff` <!---correct--> |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# This is not inside the admonition. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
text2 = """ |
|
|
|
|
|
|
|
# !!! danger "Question" |
|
|
|
|
|
|
|
# This is the Question |
|
|
|
|
|
|
|
# 1. Hello |
|
|
|
|
|
|
|
# 2. World <!---correct--> |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
parse(text2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function replace_default(content, sym; |
|
|
|
function replace_default(content, sym; |
|
|
|
config::Dict, |
|
|
|
config::Dict, |
|
|
|
branch = "gh-pages", |
|
|
|
branch = "gh-pages", |
|
|
|
@ -872,6 +851,19 @@ function writeLogic(questionName, questionDict) |
|
|
|
return logic |
|
|
|
return logic |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function writeControlFlow(questionName, qStr, toWrite) |
|
|
|
|
|
|
|
controlFlow = """ |
|
|
|
|
|
|
|
\$( |
|
|
|
|
|
|
|
if $(questionName)Test($(questionName)Answer) |
|
|
|
|
|
|
|
Markdown.MD(Markdown.Admonition("correct", "$(questionName)", [md"$(qStr)", md"$(toWrite)"])) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
Markdown.MD(Markdown.Admonition("danger", "$(questionName)", [md"$(qStr)", md"$(toWrite)"])) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
return controlFlow |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function create_notebook(flavor::PlutoFlavor, chunks, config) |
|
|
|
function create_notebook(flavor::PlutoFlavor, chunks, config) |
|
|
|
ionb = IOBuffer() |
|
|
|
ionb = IOBuffer() |
|
|
|
@ -910,14 +902,7 @@ function create_notebook(flavor::PlutoFlavor, chunks, config) |
|
|
|
if length(chunk.lines) == 1 |
|
|
|
if length(chunk.lines) == 1 |
|
|
|
line = escape_string(chunk.lines[1].second, '"') |
|
|
|
line = escape_string(chunk.lines[1].second, '"') |
|
|
|
write(io, "$(flavor.use_cm ? "cm" : "md")\"", line, "\"\n") |
|
|
|
write(io, "$(flavor.use_cm ? "cm" : "md")\"", line, "\"\n") |
|
|
|
else |
|
|
|
elseif containsAdmonition(chunk) |
|
|
|
|
|
|
|
|
|
|
|
# for line in chunk.lines |
|
|
|
|
|
|
|
# write(io, line.second, '\n') # Skip indent |
|
|
|
|
|
|
|
# end |
|
|
|
|
|
|
|
# write(io, "\"\"\"\n") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if containsAdmonition(chunk) |
|
|
|
|
|
|
|
write(io, "$(flavor.use_cm ? "cm" : "md")\"\"\"\n") |
|
|
|
write(io, "$(flavor.use_cm ? "cm" : "md")\"\"\"\n") |
|
|
|
|
|
|
|
|
|
|
|
buffer = IOBuffer() |
|
|
|
buffer = IOBuffer() |
|
|
|
@ -994,22 +979,13 @@ function create_notebook(flavor::PlutoFlavor, chunks, config) |
|
|
|
# toWrite = " " * "\$(eval(md\"\$(" * "$name" * ")\"))" * "\n" # for interactivity in the notebook (else it isn't reactive) |
|
|
|
# toWrite = " " * "\$(eval(md\"\$(" * "$name" * ")\"))" * "\n" # for interactivity in the notebook (else it isn't reactive) |
|
|
|
|
|
|
|
|
|
|
|
name = "$(questionName)Check" |
|
|
|
name = "$(questionName)Check" |
|
|
|
toWrite = "\$(" * "$name" * ")" |
|
|
|
toWrite = "\$($name)" |
|
|
|
|
|
|
|
|
|
|
|
seek(qBuf, 0) |
|
|
|
seek(qBuf, 0) |
|
|
|
qStr = read(qBuf, String) |
|
|
|
qStr = read(qBuf, String) |
|
|
|
qStr = rstrip(qStr) |
|
|
|
qStr = rstrip(qStr) |
|
|
|
|
|
|
|
|
|
|
|
result = """ |
|
|
|
result = writeControlFlow(questionName, qStr, toWrite) |
|
|
|
\$( |
|
|
|
|
|
|
|
if $(questionName)Test($(questionName)Answer) |
|
|
|
|
|
|
|
Markdown.MD(Markdown.Admonition("correct", "$(questionName)", [md"$(qStr)", md"$(toWrite)"])) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
Markdown.MD(Markdown.Admonition("danger", "$(questionName)", [md"$(qStr)", md"$(toWrite)"])) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
write(io, result, '\n') |
|
|
|
write(io, result, '\n') |
|
|
|
|
|
|
|
|
|
|
|
@ -1050,8 +1026,12 @@ function create_notebook(flavor::PlutoFlavor, chunks, config) |
|
|
|
push!(singleChoiceUuids, uuid) |
|
|
|
push!(singleChoiceUuids, uuid) |
|
|
|
push!(singleChoiceFolds, fold) |
|
|
|
push!(singleChoiceFolds, fold) |
|
|
|
push!(singleChoiceContent, content) |
|
|
|
push!(singleChoiceContent, content) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
write(io, "$(flavor.use_cm ? "cm" : "md")\"\"\"\n") |
|
|
|
|
|
|
|
for line in chunk.lines |
|
|
|
|
|
|
|
write(io, line.second, '\n') # Skip indent |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
write(io, "\"\"\"\n") |
|
|
|
end |
|
|
|
end |
|
|
|
content = String(take!(io)) |
|
|
|
content = String(take!(io)) |
|
|
|
else # isa(chunk, CodeChunk) |
|
|
|
else # isa(chunk, CodeChunk) |
|
|
|
|