Browse Source

Fix Floats disturbing answer lists (e.g. 1.0) in Pluto nb

pull/214/head
Sogari 3 years ago committed by Simon Christ
parent
commit
08faaacc7a
  1. 38
      src/Literate.jl

38
src/Literate.jl

@ -949,7 +949,6 @@ function create_notebook(flavor::PlutoFlavor, chunks, config)
str = chunkToMD(chunk) str = chunkToMD(chunk)
################################################################
# Content before the Admonition # Content before the Admonition
################################################################ ################################################################
@ -970,7 +969,7 @@ function create_notebook(flavor::PlutoFlavor, chunks, config)
end end
end end
################################################################
# The Admonition # The Admonition
################################################################ ################################################################
@ -979,13 +978,20 @@ function create_notebook(flavor::PlutoFlavor, chunks, config)
questionCategory = admonition[1].category questionCategory = admonition[1].category
str = string(Markdown.MD(admonition[1])) str = string(Markdown.MD(admonition[1]))
################################################################
# Single-Choice Admonition
################################################################
if questionCategory == "sc" if questionCategory == "sc"
answers = [] answers = []
questionDict = Dict("correct" => "") questionDict = Dict("correct" => "")
qBuf = IOBuffer() qBuf = IOBuffer()
for line in split(str, "\n") answerList = filter(x -> isa(x, Markdown.List), admonition[1].content)
println(answerList)
answerStr = string(Markdown.MD(answerList))
for line in split(answerStr, "\n")
if startswith(lstrip(line), r"[1-9]\.") if startswith(lstrip(line), r"[1-9]\.")
answer = lstrip(line) answer = lstrip(line)
@ -997,10 +1003,15 @@ function create_notebook(flavor::PlutoFlavor, chunks, config)
answer = formatAnswer(answer) answer = formatAnswer(answer)
answer = string(answer) answer = string(answer)
push!(answers, answer) push!(answers, answer)
else end
if line != "" && !startswith(line, "!!!") end
write(qBuf, lstrip(line), "\n")
end restList = filter(x -> !isa(x, Markdown.List), admonition[1].content)
restStr = string(Markdown.MD(restList))
for line in split(restStr, "\n")
if line != "" && !startswith(line, "!!!")
write(qBuf, lstrip(line), "\n")
end end
end end
@ -1013,9 +1024,8 @@ function create_notebook(flavor::PlutoFlavor, chunks, config)
result = writeControlFlow(questionName, qStr) result = writeControlFlow(questionName, qStr)
write(io, result, '\n') write(io, result, '\n')
################################################################
# Content after the Admonition # Content after the Admonition
################################################################ ############################################################
if admoIndex < length(mdContent) if admoIndex < length(mdContent)
index = admoIndex + 1 index = admoIndex + 1
@ -1028,6 +1038,8 @@ function create_notebook(flavor::PlutoFlavor, chunks, config)
write(io, "\"\"\"\n") write(io, "\"\"\"\n")
# Pluto nb helper functions # Pluto nb helper functions
############################################################
cellCounter = formatCells(io, ionb, cellCounter, uuids, folds, fold) cellCounter = formatCells(io, ionb, cellCounter, uuids, folds, fold)
write(io, radioBind, '\n') write(io, radioBind, '\n')
@ -1036,6 +1048,10 @@ function create_notebook(flavor::PlutoFlavor, chunks, config)
write(io, logicBind, '\n') write(io, logicBind, '\n')
cellCounter = formatCellsEnd(io, ionb, cellCounter, singleChoiceContent, singleChoiceUuids, singleChoiceFolds, fold) cellCounter = formatCellsEnd(io, ionb, cellCounter, singleChoiceContent, singleChoiceUuids, singleChoiceFolds, fold)
else else
############################################################
# Normal Admonitions
############################################################
index = admoIndex index = admoIndex
while index <= length(mdContent) while index <= length(mdContent)
para = string(Markdown.MD(mdContent[index])) para = string(Markdown.MD(mdContent[index]))
@ -1047,7 +1063,7 @@ function create_notebook(flavor::PlutoFlavor, chunks, config)
end end
else else
################################################################ ################################################################
# If Chunk doesnt contain an Admonition # Chunk doesnt contain an Admonition
################################################################ ################################################################
write(io, "$(flavor.use_cm ? "cm" : "md")\"\"\"\n") write(io, "$(flavor.use_cm ? "cm" : "md")\"\"\"\n")

Loading…
Cancel
Save