Browse Source

Merge 81819c61ca into 17e8ef55d0

pull/268/merge
David Métivier 4 days ago committed by GitHub
parent
commit
5f713cc31f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 20
      src/Literate.jl
  2. 14
      test/runtests.jl

20
src/Literate.jl

@ -227,6 +227,25 @@ function replace_default(
push!(repls, r"\[([^]]+?)\]\(@id .*?\)"s => s"\1") # [foo](@id bar) => foo push!(repls, r"\[([^]]+?)\]\(@id .*?\)"s => s"\1") # [foo](@id bar) => foo
# Convert Documenter admonitions to markdown quotes # Convert Documenter admonitions to markdown quotes
r = r"^# !!! (?<type>\w+)(?: \"(?<title>.+)\")?(?<lines>(\v^# .*$)+)"m r = r"^# !!! (?<type>\w+)(?: \"(?<title>.+)\")?(?<lines>(\v^# .*$)+)"m
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
else
adm_to_quote = function (s) adm_to_quote = function (s)
m = match(r, s)::RegexMatch m = match(r, s)::RegexMatch
io = IOBuffer() io = IOBuffer()
@ -243,6 +262,7 @@ function replace_default(
end end
return String(take!(io)) return String(take!(io))
end end
end
push!(repls, r => adm_to_quote) push!(repls, r => adm_to_quote)
end end

14
test/runtests.jl

@ -1531,6 +1531,20 @@ end
> on multiple lines. > on multiple lines.
""" """
@test occursin(expected, output) @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
Literate.notebook(inputfile, sandbox) Literate.notebook(inputfile, sandbox)
output = read(joinpath(sandbox, "input.ipynb"), String) output = read(joinpath(sandbox, "input.ipynb"), String)

Loading…
Cancel
Save