Browse Source

Add normal behavior when no Admonition, refactor ControlFlow

pull/214/head
Sogari 3 years ago committed by Simon Christ
parent
commit
cbe61eaf23
  1. 62
      src/Literate.jl

62
src/Literate.jl

@ -125,27 +125,6 @@ function parse(content; allow_continued = true) @@ -125,27 +125,6 @@ function parse(content; allow_continued = true)
return chunks
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;
config::Dict,
branch = "gh-pages",
@ -872,6 +851,19 @@ function writeLogic(questionName, questionDict) @@ -872,6 +851,19 @@ function writeLogic(questionName, questionDict)
return logic
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)
ionb = IOBuffer()
@ -910,14 +902,7 @@ function create_notebook(flavor::PlutoFlavor, chunks, config) @@ -910,14 +902,7 @@ function create_notebook(flavor::PlutoFlavor, chunks, config)
if length(chunk.lines) == 1
line = escape_string(chunk.lines[1].second, '"')
write(io, "$(flavor.use_cm ? "cm" : "md")\"", line, "\"\n")
else
# for line in chunk.lines
# write(io, line.second, '\n') # Skip indent
# end
# write(io, "\"\"\"\n")
if containsAdmonition(chunk)
elseif containsAdmonition(chunk)
write(io, "$(flavor.use_cm ? "cm" : "md")\"\"\"\n")
buffer = IOBuffer()
@ -994,22 +979,13 @@ function create_notebook(flavor::PlutoFlavor, chunks, config) @@ -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)
name = "$(questionName)Check"
toWrite = "\$(" * "$name" * ")"
toWrite = "\$($name)"
seek(qBuf, 0)
qStr = read(qBuf, String)
qStr = rstrip(qStr)
result = """
\$(
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
)
"""
result = writeControlFlow(questionName, qStr, toWrite)
write(io, result, '\n')
@ -1050,8 +1026,12 @@ function create_notebook(flavor::PlutoFlavor, chunks, config) @@ -1050,8 +1026,12 @@ function create_notebook(flavor::PlutoFlavor, chunks, config)
push!(singleChoiceUuids, uuid)
push!(singleChoiceFolds, fold)
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
write(io, "\"\"\"\n")
end
content = String(take!(io))
else # isa(chunk, CodeChunk)

Loading…
Cancel
Save