Skip to content

Commit

Permalink
Merge pull request #52 from jverzani/text_plain
Browse files Browse the repository at this point in the history
changes for quarto/typst rendering
  • Loading branch information
jverzani authored Nov 7, 2024
2 parents 839355d + bb497f5 commit 4f0c65a
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuizQuestions"
uuid = "612c44de-1021-4a21-84fb-7261cf5eb2d4"
authors = ["jverzani <[email protected]> and contributors"]
version = "0.3.23"
version = "0.3.24"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
83 changes: 83 additions & 0 deletions src/show_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,86 @@ function Base.show(io::IO, m::MIME"text/html", x::Scorecard)
total_questions = "{{:total_questions}}"
)
end


## ---- text/plain useful with typst conversion via quarto
function Base.show(io::IO, m::MIME"text/plain", q::Question)
length(q.label) > 0 && show(io, MIME("text/plain"), Markdown.parse(string(q.label)))
_show_plain(io, m, q)
println(io, "")
if length(q.hint) > 0
print(io, "hint: ")
show(io, MIME("text/plain"), Markdown.parse(string(q.hint)))
end
end

function _show_plain(io, m::MIME"text/plain", q::Union{Stringq, Numericq})
println(io, "")
println(io, "___________________________________________________")
end

function _show_plain(io, m::MIME"text/plain", q::Union{Scriptq})
println(io, "Answer below:")
for _ in 1:6
println(io, "")
end
end


function _show_plain(io::IO, m::MIME"text/plain",
q::Union{Radioq, Multiq, MultiButtonq})
for c q.labels
print(io, "")
show(io, MIME("text/plain"), Markdown.parse(string(c)))
println(io, "")
end
end

function _show_plain(io::IO, m::MIME"text/plain",
q::Union{Buttonq})
for c q.choices
print(io, "")
show(io, MIME("text/plain"), Markdown.parse(string(c)))
println(io, "")
end
end


function _show_plain(io::IO, m::MIME"text/plain", q::T) where {T <: Union{Matchq}}
println(io, "Match as appropriate:")
qs, cs = collect(q.questions), q.choices
for _ in (length(qs) +1):length(cs)
push!(qs, "")
end
println(io, "A B")
println(io, "-------------------------")
for (q,c) zip(qs, cs)
show(io, MIME("text/plain"), Markdown.parse(string(q)))
print(io, "\\t")
show(io, MIME("text/plain"), Markdown.parse(string(c)))
println(io, "")
end
end


function _show_plain(io::IO, m::MIME"text/plain", q::T) where {T <: FillBlankQ}
println(io, q.question)
end

function _show_plain(io::IO, m::MIME"text/plain", q::T) where {T <: Union{FillBlankChoiceQ}}
println(io, q.question)
println(io, "Choose one:")
for c q.choices
print(io, "")
show(io, MIME("text/plain"), Markdown.parse(string(c)))
println(io, "")
end
end

function _show_plain(io::IO, m::MIME"text/plain", q::T) where {T <: Union{HotspotQ, PlotlyLightQ}}
println(io, "⚠⚠⚠ Unable to display in text output ⚠⚠⚠")
end

function Base.show(io::IO, m::MIME"text/plain", q::Scorecard)
nothing
end

2 comments on commit 4f0c65a

@jverzani
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/118896

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.24 -m "<description of version>" 4f0c65a777206a57af4036094521da413f88885a
git push origin v0.3.24

Please sign in to comment.