|
|
|
@ -1,5 +1,6 @@ |
|
|
|
import Literate, JSON |
|
|
|
import Literate, JSON |
|
|
|
import Literate: Chunk, MDChunk, CodeChunk |
|
|
|
import Literate: Chunk, MDChunk, CodeChunk |
|
|
|
|
|
|
|
import Literate: pick_codefence, DefaultFlavor, QuartoFlavor |
|
|
|
using Test |
|
|
|
using Test |
|
|
|
|
|
|
|
|
|
|
|
# compare content of two parsed chunk vectors |
|
|
|
# compare content of two parsed chunk vectors |
|
|
|
@ -108,6 +109,8 @@ end |
|
|
|
## Line 77 |
|
|
|
## Line 77 |
|
|
|
## |
|
|
|
## |
|
|
|
## Line 79 |
|
|
|
## Line 79 |
|
|
|
|
|
|
|
# Line 80: Quarto Specific |
|
|
|
|
|
|
|
##| Line 81 |
|
|
|
""" |
|
|
|
""" |
|
|
|
expected_chunks = Chunk[ |
|
|
|
expected_chunks = Chunk[ |
|
|
|
MDChunk(["" => "Line 1"]), |
|
|
|
MDChunk(["" => "Line 1"]), |
|
|
|
@ -145,10 +148,55 @@ end |
|
|
|
CodeChunk(["Line 64", " # Line 65", " Line 66", "Line 67"], false), |
|
|
|
CodeChunk(["Line 64", " # Line 65", " Line 66", "Line 67"], false), |
|
|
|
CodeChunk(["# Line 73", "#", "# Line 75"], false), |
|
|
|
CodeChunk(["# Line 73", "#", "# Line 75"], false), |
|
|
|
CodeChunk([" # Line 77", " #", " # Line 79"], false), |
|
|
|
CodeChunk([" # Line 77", " #", " # Line 79"], false), |
|
|
|
] |
|
|
|
MDChunk(["" => "Line 80: Quarto Specific"]), |
|
|
|
parsed_chunks = Literate.parse(content) |
|
|
|
CodeChunk(["##| Line 81"], false) |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
parsed_chunks = Literate.parse(DefaultFlavor(), content) |
|
|
|
compare_chunks(parsed_chunks, expected_chunks) |
|
|
|
compare_chunks(parsed_chunks, expected_chunks) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# QuartoFlavor parsing semantics |
|
|
|
|
|
|
|
expected_chunks_quarto = Chunk[ |
|
|
|
|
|
|
|
MDChunk(["" => "Line 1"]), |
|
|
|
|
|
|
|
CodeChunk(["Line 2"], false), |
|
|
|
|
|
|
|
MDChunk(["" => "Line 3", "" => "","" => "Line 5"]), |
|
|
|
|
|
|
|
CodeChunk(["Line 6", "","Line 8"], false), |
|
|
|
|
|
|
|
MDChunk(["" => "Line 9"]), |
|
|
|
|
|
|
|
MDChunk(["" => "Line 11"]), |
|
|
|
|
|
|
|
CodeChunk(["Line 12"], false), |
|
|
|
|
|
|
|
CodeChunk(["Line 14"], false), |
|
|
|
|
|
|
|
MDChunk(["" => "Line 15"]), |
|
|
|
|
|
|
|
MDChunk(["" => "Line 17"]), |
|
|
|
|
|
|
|
CodeChunk(["Line 18"], false), |
|
|
|
|
|
|
|
CodeChunk(["Line 20"], false), |
|
|
|
|
|
|
|
MDChunk(["" => "Line 21"]), |
|
|
|
|
|
|
|
CodeChunk(["Line 22", " Line 23", "Line 24"], false), |
|
|
|
|
|
|
|
CodeChunk(["Line 26", " Line 27"], true), |
|
|
|
|
|
|
|
CodeChunk(["Line 29"], false), |
|
|
|
|
|
|
|
CodeChunk(["Line 31", " Line 32"], true), |
|
|
|
|
|
|
|
MDChunk(["" => "Line 33"]), |
|
|
|
|
|
|
|
CodeChunk(["Line 34"], false), |
|
|
|
|
|
|
|
CodeChunk(["Line 36"], true), |
|
|
|
|
|
|
|
CodeChunk([" Line 38"], true), |
|
|
|
|
|
|
|
CodeChunk(["Line 40"], false), |
|
|
|
|
|
|
|
CodeChunk(["Line 42", " Line 43"], true), |
|
|
|
|
|
|
|
MDChunk(["" => "Line 44"]), |
|
|
|
|
|
|
|
CodeChunk([" Line 45"], true), |
|
|
|
|
|
|
|
MDChunk(["" => "Line 46"]), |
|
|
|
|
|
|
|
CodeChunk(["Line 47"], false), |
|
|
|
|
|
|
|
MDChunk(["" => "Line 48"]), |
|
|
|
|
|
|
|
CodeChunk(["#Line 49", "Line 50"], false), |
|
|
|
|
|
|
|
MDChunk(["" => "Line 53"]), |
|
|
|
|
|
|
|
CodeChunk(["# Line 57", "Line 58", "# Line 59", "##Line 60"], false), |
|
|
|
|
|
|
|
MDChunk([" " => "Line 62", " " => "# Line 63"]), |
|
|
|
|
|
|
|
CodeChunk(["Line 64", " # Line 65", " Line 66", "Line 67"], false), |
|
|
|
|
|
|
|
CodeChunk(["# Line 73", "#", "# Line 75"], false), |
|
|
|
|
|
|
|
CodeChunk([" # Line 77", " #", " # Line 79"], false), |
|
|
|
|
|
|
|
MDChunk(["" => "Line 80: Quarto Specific"]), |
|
|
|
|
|
|
|
CodeChunk(["#| Line 81"], false) # parses correctly as code cell command |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
parsed_chunks = Literate.parse(QuartoFlavor(), content) |
|
|
|
|
|
|
|
compare_chunks(parsed_chunks, expected_chunks_quarto) |
|
|
|
|
|
|
|
|
|
|
|
# test leading/trailing whitespace removal |
|
|
|
# test leading/trailing whitespace removal |
|
|
|
io = IOBuffer() |
|
|
|
io = IOBuffer() |
|
|
|
iows = IOBuffer() |
|
|
|
iows = IOBuffer() |
|
|
|
@ -165,7 +213,7 @@ end |
|
|
|
foreach(x -> println(iows), 1:rand(2:5)) |
|
|
|
foreach(x -> println(iows), 1:rand(2:5)) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
compare_chunks(Literate.parse(String(take!(io))), Literate.parse(String(take!(iows)))) |
|
|
|
compare_chunks(Literate.parse(DefaultFlavor(), String(take!(io))), Literate.parse(DefaultFlavor(), String(take!(iows)))) |
|
|
|
|
|
|
|
|
|
|
|
end # testset parser |
|
|
|
end # testset parser |
|
|
|
|
|
|
|
|
|
|
|
@ -753,6 +801,19 @@ end end |
|
|
|
@test !occursin("EditURL", markdown) |
|
|
|
@test !occursin("EditURL", markdown) |
|
|
|
@test !occursin("#hide", markdown) |
|
|
|
@test !occursin("#hide", markdown) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# flavor = QuartoFlavor() |
|
|
|
|
|
|
|
# execution of Quarto markdown is not allowed |
|
|
|
|
|
|
|
let expected_error = ArgumentError("QuartoFlavor does not support `execute = true`.") |
|
|
|
|
|
|
|
@test_throws expected_error Literate.markdown("quarto.jl", flavor = Literate.QuartoFlavor(), execute = true) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
Literate.markdown(inputfile, outdir, flavor = Literate.QuartoFlavor(),execute=false) |
|
|
|
|
|
|
|
markdown = read(joinpath(outdir, "inputfile.qmd"), String) |
|
|
|
|
|
|
|
@test occursin("```{julia}", markdown) |
|
|
|
|
|
|
|
@test !occursin(r"`{3,}@example", markdown) |
|
|
|
|
|
|
|
@test !occursin("continued = true", markdown) |
|
|
|
|
|
|
|
@test !occursin("EditURL", markdown) |
|
|
|
|
|
|
|
@test !occursin("#hide", markdown) |
|
|
|
|
|
|
|
|
|
|
|
# documenter = false (deprecated) |
|
|
|
# documenter = false (deprecated) |
|
|
|
@test_deprecated r"The documenter=true keyword to Literate.markdown is deprecated" begin |
|
|
|
@test_deprecated r"The documenter=true keyword to Literate.markdown is deprecated" begin |
|
|
|
Literate.markdown(inputfile, outdir, documenter = true) |
|
|
|
Literate.markdown(inputfile, outdir, documenter = true) |
|
|
|
@ -880,6 +941,11 @@ end end |
|
|
|
@test occursin("# MD", markdown) # text/markdown |
|
|
|
@test occursin("# MD", markdown) # text/markdown |
|
|
|
@test occursin("~~~\n<h1>MD</h1>\n~~~", markdown) # text/html |
|
|
|
@test occursin("~~~\n<h1>MD</h1>\n~~~", markdown) # text/html |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# QuartoFlavor file extension |
|
|
|
|
|
|
|
write(inputfile, "#=\r\nhello world\n=#\r\n") |
|
|
|
|
|
|
|
_, config = Literate.preprocessor(inputfile, outdir; user_kwargs=(), user_config=Dict("flavor"=>Literate.QuartoFlavor()), type=:md) |
|
|
|
|
|
|
|
@test config["literate_ext"] == ".qmd" |
|
|
|
|
|
|
|
|
|
|
|
# verify that inputfile exists |
|
|
|
# verify that inputfile exists |
|
|
|
@test_throws ArgumentError Literate.markdown("nonexistent.jl", outdir) |
|
|
|
@test_throws ArgumentError Literate.markdown("nonexistent.jl", outdir) |
|
|
|
|
|
|
|
|
|
|
|
@ -1406,6 +1472,16 @@ end end |
|
|
|
@test occursin("Link to nbviewer: www.example2.com/file.jl", script) |
|
|
|
@test occursin("Link to nbviewer: www.example2.com/file.jl", script) |
|
|
|
@test occursin("Link to binder: www.example3.com/file.jl", script) |
|
|
|
@test occursin("Link to binder: www.example3.com/file.jl", script) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test pick_codefence function |
|
|
|
|
|
|
|
default_codefence=pick_codefence(Literate.DefaultFlavor(), true, "testname") |
|
|
|
|
|
|
|
@test default_codefence == ("````julia" => "````") |
|
|
|
|
|
|
|
@test default_codefence == pick_codefence(Literate.FranklinFlavor(), true, "testname") |
|
|
|
|
|
|
|
@test default_codefence == pick_codefence(Literate.DocumenterFlavor(), true, "testname") |
|
|
|
|
|
|
|
documenter_codefence = ("````@example testname" => "````") |
|
|
|
|
|
|
|
@test documenter_codefence == pick_codefence(Literate.DocumenterFlavor(), false, "testname") |
|
|
|
|
|
|
|
@test ("```{julia}" => "```") == pick_codefence(Literate.QuartoFlavor(), true, "testname") |
|
|
|
|
|
|
|
@test ("```{julia}" => "```") == pick_codefence(Literate.QuartoFlavor(), false, "testname") |
|
|
|
|
|
|
|
|
|
|
|
# Misc default configs |
|
|
|
# Misc default configs |
|
|
|
create(; type, kw...) = Literate.create_configuration(inputfile; user_config=Dict(), user_kwargs=kw, type=type) |
|
|
|
create(; type, kw...) = Literate.create_configuration(inputfile; user_config=Dict(), user_kwargs=kw, type=type) |
|
|
|
cfg = create(; type=:md, execute=true) |
|
|
|
cfg = create(; type=:md, execute=true) |
|
|
|
|