From f100043b074b59d7ba1e6aae50ad7076c72368cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20M=C3=A9tivier?= <46794064+dmetivie@users.noreply.github.com> Date: Tue, 21 Jan 2025 09:54:43 +0100 Subject: [PATCH 1/2] add support for quarto Callout Blocks --- src/Literate.jl | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/Literate.jl b/src/Literate.jl index 2e381fc..be5fa7c 100644 --- a/src/Literate.jl +++ b/src/Literate.jl @@ -227,21 +227,41 @@ function replace_default( push!(repls, r"\[([^]]+?)\]\(@id .*?\)"s => s"\1") # [foo](@id bar) => foo # Convert Documenter admonitions to markdown quotes r = r"^# !!! (?\w+)(?: \"(?.+)\")?(?<lines>(\v^# .*$)+)"m - adm_to_quote = function (s) - m = match(r, s)::RegexMatch - io = IOBuffer() - print(io, "# > **") - if (title = m[:title]; title !== nothing) - print(io, title) - else - type = uppercasefirst(String(m[:type])) - print(io, type) + if config["flavor"] isa QuartoFlavor + adm_to_quote = function (s) + m = match(r, s)::RegexMatch + io = IOBuffer() + print(io, "# ::: {.callout-") # to open the callout + print(io, string(m[:type])) + if (title = m[:title]; title !== nothing) + print(io, s""" title=\"""") + print(io, title) + print(io, s"""\"""") + end + print(io, "}") # not sure how to detect the Quarto `collapse` option if any + for l in eachline(IOBuffer(m[:lines]); keep = true) + print(io, replace(l, r"^# " => "# ")) + end + print(io, "\n# :::") # to close the callout + return String(take!(io)) end - print(io, "**\n# >") - for l in eachline(IOBuffer(m[:lines]); keep = true) - print(io, replace(l, r"^# " => "# > ")) + else + adm_to_quote = function (s) + m = match(r, s)::RegexMatch + io = IOBuffer() + print(io, "# > **") + if (title = m[:title]; title !== nothing) + print(io, title) + else + type = uppercasefirst(String(m[:type])) + print(io, type) + end + print(io, "**\n# >") + for l in eachline(IOBuffer(m[:lines]); keep = true) + print(io, replace(l, r"^# " => "# > ")) + end + return String(take!(io)) end - return String(take!(io)) end push!(repls, r => adm_to_quote) end From 81819c61cafe51ee73fe0f44d10513a969613c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20M=C3=A9tivier?= <46794064+dmetivie@users.noreply.github.com> Date: Tue, 21 Jan 2025 09:55:40 +0100 Subject: [PATCH 2/2] add test for quarto callout block --- test/runtests.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 2040685..f505fd7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1531,6 +1531,20 @@ end > on multiple lines. """ @test occursin(expected, output) + # Literate.markdown Literate.QuartoFlavor() + Literate.markdown(inputfile, sandbox; flavor = Literate.QuartoFlavor()) + output = read(joinpath(sandbox, "input.qmd"), String) + expected = """ + ::: {.callout-note} + This is a note on one line. + ::: + + ::: {.callout-warn title="Warning title text"} + This is a warning + on multiple lines. + ::: + """ + @test occursin(expected, output) # Literate.notebook Literate.notebook(inputfile, sandbox) output = read(joinpath(sandbox, "input.ipynb"), String)