Browse Source

Apply Runic formatting (#266)

pull/275/head
Fredrik Ekre 12 months ago committed by GitHub
parent
commit
5d1b4918b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 23
      .github/workflows/Check.yml
  2. 2
      README.md
  3. 4
      docs/make.jl
  4. 4
      docs/src/outputformats.jl
  5. 2
      examples/README.jl
  6. 6
      examples/example.jl
  7. 6
      src/IJulia.jl
  8. 177
      src/Literate.jl
  9. 498
      test/runtests.jl

23
.github/workflows/Check.yml

@ -0,0 +1,23 @@
---
name: Check
on:
push:
branches:
- 'master'
- 'release-'
tags:
- '*'
pull_request:
jobs:
runic:
name: Runic formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: '1.11'
- uses: julia-actions/cache@v2
- uses: fredrikekre/runic-action@v1
with:
version: '1.2'

2
README.md

@ -21,7 +21,7 @@ running these commands from the package root of Literate.jl:
````julia ````julia
using Literate using Literate
Literate.markdown("examples/README.jl", "."; flavor=Literate.CommonMarkFlavor()) Literate.markdown("examples/README.jl", "."; flavor = Literate.CommonMarkFlavor())
```` ````
### Related packages ### Related packages

4
docs/make.jl

@ -5,7 +5,7 @@ if haskey(ENV, "GITHUB_ACTIONS")
end end
deployconfig = Documenter.auto_detect_deploy_system() deployconfig = Documenter.auto_detect_deploy_system()
Documenter.post_status(deployconfig; type="pending", repo="github.com/fredrikekre/Literate.jl.git") Documenter.post_status(deployconfig; type = "pending", repo = "github.com/fredrikekre/Literate.jl.git")
using Literate using Literate
using Plots # to not capture precompilation output using Plots # to not capture precompilation output
@ -14,7 +14,7 @@ EXAMPLE = joinpath(@__DIR__, "..", "examples", "example.jl")
OUTPUT = joinpath(@__DIR__, "src/generated") OUTPUT = joinpath(@__DIR__, "src/generated")
function preprocess(str) function preprocess(str)
str = replace(str, "x = 123" => "y = 321"; count=1) str = replace(str, "x = 123" => "y = 321"; count = 1)
return str return str
end end

4
docs/src/outputformats.jl

@ -3,9 +3,9 @@
# In julia rational numbers can be constructed with the `//` operator. # In julia rational numbers can be constructed with the `//` operator.
# Lets define two rational numbers, `x` and `y`: # Lets define two rational numbers, `x` and `y`:
x = 1//3 x = 1 // 3
#- #-
y = 2//5 y = 2 // 5
# When adding `x` and `y` together we obtain a new rational number: # When adding `x` and `y` together we obtain a new rational number:

2
examples/README.jl

@ -20,7 +20,7 @@
# running these commands from the package root of Literate.jl: # running these commands from the package root of Literate.jl:
using Literate using Literate
Literate.markdown("examples/README.jl", "."; flavor=Literate.CommonMarkFlavor()) Literate.markdown("examples/README.jl", "."; flavor = Literate.CommonMarkFlavor())
# ### Related packages # ### Related packages

6
examples/example.jl

@ -33,8 +33,8 @@
# as markdown, and all the other lines are interpreted as code. Here is some code: # as markdown, and all the other lines are interpreted as code. Here is some code:
#nb %% A slide [code] {"slideshow": {"slide_type": "fragment"}} #nb %% A slide [code] {"slideshow": {"slide_type": "fragment"}}
x = 1//3 x = 1 // 3
y = 2//5 y = 2 // 5
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "subslide"}} #nb # %% A slide [markdown] {"slideshow": {"slide_type": "subslide"}}
# In markdown sections we can use markdown syntax. For example, we can # In markdown sections we can use markdown syntax. For example, we can
@ -96,7 +96,7 @@ foo()
#nb %% A slide [code] {"slideshow": {"slide_type": "subslide"}} #nb %% A slide [code] {"slideshow": {"slide_type": "subslide"}}
using Plots using Plots
x = range(0, stop=6π, length=1000) x = range(0, stop = 6π, length = 1000)
y1 = sin.(x) y1 = sin.(x)
y2 = cos.(x) y2 = cos.(x)
plot(x, [y1, y2]) plot(x, [y1, y2])

6
src/IJulia.jl

@ -17,7 +17,7 @@ const application_vnd_vegalite_v2 = MIME("application/vnd.vegalite.v2+json")
# return a String=>String dictionary of mimetype=>data # return a String=>String dictionary of mimetype=>data
# for passing to Jupyter display_data and execute_result messages. # for passing to Jupyter display_data and execute_result messages.
function display_dict(x) function display_dict(x)
data = Dict{String,Any}("text/plain" => limitstringmime(text_plain, x)) data = Dict{String, Any}("text/plain" => limitstringmime(text_plain, x))
if showable(application_vnd_vegalite_v2, x) if showable(application_vnd_vegalite_v2, x)
data[string(application_vnd_vegalite_v2)] = JSON.parse(limitstringmime(application_vnd_vegalite_v2, x)) data[string(application_vnd_vegalite_v2)] = JSON.parse(limitstringmime(application_vnd_vegalite_v2, x))
end end
@ -57,14 +57,14 @@ function limitstringmime(mime::MIME, x)
if israwtext(mime, x) if israwtext(mime, x)
return String(x) return String(x)
else else
show(IOContext(buf, :limit=>true, :color=>true), mime, x) show(IOContext(buf, :limit => true, :color => true), mime, x)
end end
else else
b64 = Base64EncodePipe(buf) b64 = Base64EncodePipe(buf)
if isa(x, Vector{UInt8}) if isa(x, Vector{UInt8})
write(b64, x) # x assumed to be raw binary data write(b64, x) # x assumed to be raw binary data
else else
show(IOContext(b64, :limit=>true, :color=>true), mime, x) show(IOContext(b64, :limit => true, :color => true), mime, x)
end end
close(b64) close(b64)
end end

177
src/Literate.jl

@ -39,7 +39,7 @@ struct QuartoFlavor <: AbstractFlavor end
# Parser # Parser
abstract type Chunk end abstract type Chunk end
struct MDChunk <: Chunk struct MDChunk <: Chunk
lines::Vector{Pair{String,String}} # indent and content lines::Vector{Pair{String, String}} # indent and content
end end
MDChunk() = MDChunk(String[]) MDChunk() = MDChunk(String[])
mutable struct CodeChunk <: Chunk mutable struct CodeChunk <: Chunk
@ -133,12 +133,10 @@ function parse(flavor::AbstractFlavor, content; allow_continued = true)
return chunks return chunks
end end
function replace_default(content, sym; function replace_default(
config::Dict, content, sym; config::Dict, branch = "gh-pages", commit = "master"
branch = "gh-pages",
commit = "master"
) )
repls = Pair{Any,Any}[] repls = Pair{Any, Any}[]
# add some shameless advertisement # add some shameless advertisement
if config["credit"]::Bool if config["credit"]::Bool
@ -168,7 +166,7 @@ function replace_default(content, sym;
newlines = sprint() do io newlines = sprint() do io
foreach(l -> println(io, "# ", l), eachline(IOBuffer(m[1]))) foreach(l -> println(io, "# ", l), eachline(IOBuffer(m[1])))
end end
str = replace(str, multiline_r => chop(newlines); count=1) str = replace(str, multiline_r => chop(newlines); count = 1)
end end
return str return str
end end
@ -229,7 +227,7 @@ function replace_default(content, sym;
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
adm_to_quote = function(s) adm_to_quote = function (s)
m = match(r, s)::RegexMatch m = match(r, s)::RegexMatch
io = IOBuffer() io = IOBuffer()
print(io, "# > **") print(io, "# > **")
@ -259,11 +257,13 @@ end
filename(str) = first(splitext(last(splitdir(str)))) filename(str) = first(splitext(last(splitdir(str))))
isdocumenter(cfg) = cfg["flavor"]::AbstractFlavor isa DocumenterFlavor isdocumenter(cfg) = cfg["flavor"]::AbstractFlavor isa DocumenterFlavor
_DEFAULT_IMAGE_FORMATS = [(MIME("image/svg+xml"), ".svg"), (MIME("image/png"), ".png"), _DEFAULT_IMAGE_FORMATS = [
(MIME("image/jpeg"), ".jpeg")] (MIME("image/svg+xml"), ".svg"), (MIME("image/png"), ".png"),
(MIME("image/jpeg"), ".jpeg"),
]
# Cache of inputfile => head branch # Cache of inputfile => head branch
const HEAD_BRANCH_CACHE = Dict{String,String}() const HEAD_BRANCH_CACHE = Dict{String, String}()
# Guess the package (or repository) root url with "master" as fallback # Guess the package (or repository) root url with "master" as fallback
# see JuliaDocs/Documenter.jl#1751 # see JuliaDocs/Documenter.jl#1751
@ -277,8 +277,8 @@ function edit_commit(inputfile, user_config)
git_root = try git_root = try
readchomp( readchomp(
pipeline( pipeline(
setenv(`$(git) rev-parse --show-toplevel`; dir=dirname(inputfile)); setenv(`$(git) rev-parse --show-toplevel`; dir = dirname(inputfile));
stderr=devnull, stderr = devnull,
) )
) )
catch catch
@ -298,8 +298,8 @@ function edit_commit(inputfile, user_config)
str = try str = try
read( read(
pipeline( pipeline(
setenv(`$(git) remote show origin`, env; dir=dirname(inputfile)), setenv(`$(git) remote show origin`, env; dir = dirname(inputfile)),
stderr=devnull, stderr = devnull,
), ),
String, String,
) )
@ -332,30 +332,38 @@ function pick_codefence(::QuartoFlavor, execute::Bool, name::AbstractString)
return "```{julia}" => "```" return "```{julia}" => "```"
end end
function create_configuration(inputfile; user_config, user_kwargs, type=nothing) function create_configuration(inputfile; user_config, user_kwargs, type = nothing)
# Combine user config with user kwargs # Combine user config with user kwargs
user_config = Dict{String,Any}(string(k) => v for (k, v) in user_config) user_config = Dict{String, Any}(string(k) => v for (k, v) in user_config)
user_kwargs = Dict{String,Any}(string(k) => v for (k, v) in user_kwargs) user_kwargs = Dict{String, Any}(string(k) => v for (k, v) in user_kwargs)
user_config = merge!(user_config, user_kwargs) user_config = merge!(user_config, user_kwargs)
# deprecation of documenter kwarg # deprecation of documenter kwarg
if (d = get(user_config, "documenter", nothing); d !== nothing) if (d = get(user_config, "documenter", nothing); d !== nothing)
if type === :md if type === :md
Base.depwarn("The documenter=$(d) keyword to Literate.markdown is deprecated." * Base.depwarn(
"The documenter=$(d) keyword to Literate.markdown is deprecated." *
" Pass `flavor = Literate.$(d ? "DocumenterFlavor" : "CommonMarkFlavor")()`" * " Pass `flavor = Literate.$(d ? "DocumenterFlavor" : "CommonMarkFlavor")()`" *
" instead.", Symbol("Literate.markdown")) " instead.", Symbol("Literate.markdown")
)
user_config["flavor"] = d ? DocumenterFlavor() : CommonMarkFlavor() user_config["flavor"] = d ? DocumenterFlavor() : CommonMarkFlavor()
elseif type === :nb elseif type === :nb
Base.depwarn("The documenter=$(d) keyword to Literate.notebook is deprecated." * Base.depwarn(
" It is not used anymore for notebook output.", Symbol("Literate.notebook")) "The documenter=$(d) keyword to Literate.notebook is deprecated." *
" It is not used anymore for notebook output.",
Symbol("Literate.notebook")
)
elseif type === :jl elseif type === :jl
Base.depwarn("The documenter=$(d) keyword to Literate.script is deprecated." * Base.depwarn(
" It is not used anymore for script output.", Symbol("Literate.script")) "The documenter=$(d) keyword to Literate.script is deprecated." *
" It is not used anymore for script output.",
Symbol("Literate.script")
)
end end
end end
# Add default config # Add default config
cfg = Dict{String,Any}() cfg = Dict{String, Any}()
cfg["name"] = filename(inputfile) cfg["name"] = filename(inputfile)
cfg["preprocess"] = identity cfg["preprocess"] = identity
cfg["postprocess"] = identity cfg["postprocess"] = identity
@ -479,12 +487,13 @@ Available options:
`$(_DEFAULT_IMAGE_FORMATS)`. Results which are `showable` with a MIME type are saved with `$(_DEFAULT_IMAGE_FORMATS)`. Results which are `showable` with a MIME type are saved with
the first match, with the corresponding extension. the first match, with the corresponding extension.
""" """
const DEFAULT_CONFIGURATION=nothing # Dummy const for documentation const DEFAULT_CONFIGURATION = nothing # Dummy const for documentation
function preprocessor(inputfile, outputdir; user_config, user_kwargs, type) function preprocessor(inputfile, outputdir; user_config, user_kwargs, type)
# Create configuration by merging default and userdefined # Create configuration by merging default and userdefined
config = create_configuration(inputfile; user_config=user_config, config = create_configuration(
user_kwargs=user_kwargs, type=type) inputfile; user_config = user_config, user_kwargs = user_kwargs, type = type
)
# Quarto output does not support execute = true # Quarto output does not support execute = true
if config["flavor"] isa QuartoFlavor && config["execute"] if config["flavor"] isa QuartoFlavor && config["execute"]
@ -526,16 +535,17 @@ function preprocessor(inputfile, outputdir; user_config, user_kwargs, type)
# change the Edit on GitHub link # change the Edit on GitHub link
edit_url = relpath(inputfile, config["literate_outputdir"]) edit_url = relpath(inputfile, config["literate_outputdir"])
edit_url = replace(edit_url, "\\" => "/") edit_url = replace(edit_url, "\\" => "/")
content = """ meta_block = """
# ```@meta # ```@meta
# EditURL = "$(edit_url)" # EditURL = "$(edit_url)"
# ``` # ```
""" * content """
content = meta_block * content
end end
# default replacements # default replacements
content = replace_default(content, type; config=config) content = replace_default(content, type; config = config)
# parse the content into chunks # parse the content into chunks
chunks = parse(config["flavor"], content; allow_continued = type !== :nb) chunks = parse(config["flavor"], content; allow_continued = type !== :nb)
@ -543,7 +553,7 @@ function preprocessor(inputfile, outputdir; user_config, user_kwargs, type)
return chunks, config return chunks, config
end end
function write_result(content, config; print=print) function write_result(content, config; print = print)
outputfile = config["literate_outputfile"] outputfile = config["literate_outputfile"]
@info "writing result to `$(Base.contractuser(outputfile))`" @info "writing result to `$(Base.contractuser(outputfile))`"
open(outputfile, "w") do io open(outputfile, "w") do io
@ -560,10 +570,10 @@ Generate a plain script file from `inputfile` and write the result to `outputdir
See the manual section on [Configuration](@ref) for documentation See the manual section on [Configuration](@ref) for documentation
of possible configuration with `config` and other keyword arguments. of possible configuration with `config` and other keyword arguments.
""" """
function script(inputfile, outputdir=pwd(); config::AbstractDict=Dict(), kwargs...) function script(inputfile, outputdir = pwd(); config::AbstractDict = Dict(), kwargs...)
# preprocessing and parsing # preprocessing and parsing
chunks, config = chunks, config =
preprocessor(inputfile, outputdir; user_config=config, user_kwargs=kwargs, type=:jl) preprocessor(inputfile, outputdir; user_config = config, user_kwargs = kwargs, type = :jl)
# create the script file # create the script file
ioscript = IOBuffer() ioscript = IOBuffer()
@ -600,10 +610,10 @@ to the directory `outputdir`.
See the manual section on [Configuration](@ref) for documentation See the manual section on [Configuration](@ref) for documentation
of possible configuration with `config` and other keyword arguments. of possible configuration with `config` and other keyword arguments.
""" """
function markdown(inputfile, outputdir=pwd(); config::AbstractDict=Dict(), kwargs...) function markdown(inputfile, outputdir = pwd(); config::AbstractDict = Dict(), kwargs...)
# preprocessing and parsing # preprocessing and parsing
chunks, config = chunks, config =
preprocessor(inputfile, outputdir; user_config=config, user_kwargs=kwargs, type=:md) preprocessor(inputfile, outputdir; user_config = config, user_kwargs = kwargs, type = :md)
# create the markdown file # create the markdown file
sb = sandbox() sb = sandbox()
@ -637,15 +647,16 @@ function markdown(inputfile, outputdir=pwd(); config::AbstractDict=Dict(), kwarg
any(write_line, chunk.lines) && write(iomd, seekstart(iocode)) any(write_line, chunk.lines) && write(iomd, seekstart(iocode))
if execute if execute
cd(config["literate_outputdir"]) do cd(config["literate_outputdir"]) do
execute_markdown!(iomd, sb, join(chunk.lines, '\n'), execute_markdown!(
iomd, sb, join(chunk.lines, '\n'),
config["literate_outputdir"]; config["literate_outputdir"];
inputfile=config["literate_inputfile"], inputfile = config["literate_inputfile"],
fake_source=config["literate_outputfile"], fake_source = config["literate_outputfile"],
flavor=config["flavor"], flavor = config["flavor"],
image_formats=config["image_formats"], image_formats = config["image_formats"],
file_prefix="$(config["name"])-$(chunknum)", file_prefix = "$(config["name"])-$(chunknum)",
softscope=config["softscope"], softscope = config["softscope"],
continue_on_error=config["continue_on_error"], continue_on_error = config["continue_on_error"],
) )
end end
end end
@ -661,13 +672,17 @@ function markdown(inputfile, outputdir=pwd(); config::AbstractDict=Dict(), kwarg
return outputfile return outputfile
end end
function execute_markdown!(io::IO, sb::Module, block::String, outputdir; function execute_markdown!(
inputfile::String, fake_source::String, io::IO, sb::Module, block::String, outputdir;
flavor::AbstractFlavor, image_formats::Vector, file_prefix::String, inputfile::String, fake_source::String, flavor::AbstractFlavor,
softscope::Bool, continue_on_error::Bool) image_formats::Vector, file_prefix::String, softscope::Bool,
continue_on_error::Bool
)
# TODO: Deal with explicit display(...) calls # TODO: Deal with explicit display(...) calls
r, str, _ = execute_block(sb, block; inputfile=inputfile, fake_source=fake_source, r, str, _ = execute_block(
softscope=softscope, continue_on_error=continue_on_error) sb, block; inputfile = inputfile, fake_source = fake_source,
softscope = softscope, continue_on_error = continue_on_error
)
# issue #101: consecutive codefenced blocks need newline # issue #101: consecutive codefenced blocks need newline
# issue #144: quadruple backticks allow for triple backticks in the output # issue #144: quadruple backticks allow for triple backticks in the output
plain_fence = "\n````\n" => "\n````" plain_fence = "\n````\n" => "\n````"
@ -731,16 +746,16 @@ Generate a notebook from `inputfile` and write the result to `outputdir`.
See the manual section on [Configuration](@ref) for documentation See the manual section on [Configuration](@ref) for documentation
of possible configuration with `config` and other keyword arguments. of possible configuration with `config` and other keyword arguments.
""" """
function notebook(inputfile, outputdir=pwd(); config::AbstractDict=Dict(), kwargs...) function notebook(inputfile, outputdir = pwd(); config::AbstractDict = Dict(), kwargs...)
# preprocessing and parsing # preprocessing and parsing
chunks, config = chunks, config =
preprocessor(inputfile, outputdir; user_config=config, user_kwargs=kwargs, type=:nb) preprocessor(inputfile, outputdir; user_config = config, user_kwargs = kwargs, type = :nb)
# create the notebook # create the notebook
nb = jupyter_notebook(chunks, config) nb = jupyter_notebook(chunks, config)
# write to file # write to file
outputfile = write_result(nb, config; print = (io, c)->JSON.print(io, c, 1)) outputfile = write_result(nb, config; print = (io, c) -> JSON.print(io, c, 1))
return outputfile return outputfile
end end
@ -761,10 +776,12 @@ function jupyter_notebook(chunks, config)
else else
metadata = Dict{String, Any}() metadata = Dict{String, Any}()
end end
lines = isa(chunk, MDChunk) ? if isa(chunk, MDChunk)
String[x.second for x in chunk.lines] : # skip indent lines = String[x.second for x in chunk.lines] # skip indent
chunk.lines else
@views map!(x -> x * '\n', lines[1:end-1], lines[1:end-1]) lines = chunk.lines
end
@views map!(x -> x * '\n', lines[1:(end - 1)], lines[1:(end - 1)])
cell["cell_type"] = chunktype cell["cell_type"] = chunktype
cell["metadata"] = metadata cell["metadata"] = metadata
cell["source"] = lines cell["source"] = lines
@ -788,7 +805,7 @@ function jupyter_notebook(chunks, config)
language_info = Dict() language_info = Dict()
language_info["file_extension"] = ".jl" language_info["file_extension"] = ".jl"
language_info["mimetype"] = "application/julia" language_info["mimetype"] = "application/julia"
language_info["name"]= "julia" language_info["name"] = "julia"
language_info["version"] = string(VERSION) language_info["version"] = string(VERSION)
metadata["language_info"] = language_info metadata["language_info"] = language_info
@ -801,11 +818,12 @@ function jupyter_notebook(chunks, config)
@info "executing notebook `$(config["name"] * ".ipynb")`" @info "executing notebook `$(config["name"] * ".ipynb")`"
try try
cd(config["literate_outputdir"]) do cd(config["literate_outputdir"]) do
nb = execute_notebook(nb; inputfile=config["literate_inputfile"], nb = execute_notebook(
fake_source=config["literate_outputfile"], nb; inputfile = config["literate_inputfile"],
softscope=config["softscope"], fake_source = config["literate_outputfile"],
continue_on_error=config["continue_on_error"], softscope = config["softscope"],
) continue_on_error = config["continue_on_error"],
)
end end
catch err catch err
@error "error when executing notebook based on input file: " * @error "error when executing notebook based on input file: " *
@ -816,8 +834,10 @@ function jupyter_notebook(chunks, config)
return nb return nb
end end
function execute_notebook(nb; inputfile::String, fake_source::String, softscope::Bool, function execute_notebook(
continue_on_error=continue_on_error) nb; inputfile::String, fake_source::String, softscope::Bool,
continue_on_error = continue_on_error
)
sb = sandbox() sb = sandbox()
execution_count = 0 execution_count = 0
for cell in nb["cells"] for cell in nb["cells"]
@ -825,13 +845,14 @@ function execute_notebook(nb; inputfile::String, fake_source::String, softscope:
execution_count += 1 execution_count += 1
cell["execution_count"] = execution_count cell["execution_count"] = execution_count
block = join(cell["source"]) block = join(cell["source"])
r, str, display_dicts = execute_block(sb, block; inputfile=inputfile, r, str, display_dicts = execute_block(
fake_source=fake_source, softscope=softscope, sb, block; inputfile = inputfile, fake_source = fake_source,
continue_on_error=continue_on_error) softscope = softscope, continue_on_error = continue_on_error
)
# str should go into stream # str should go into stream
if !isempty(str) if !isempty(str)
stream = Dict{String,Any}() stream = Dict{String, Any}()
stream["output_type"] = "stream" stream["output_type"] = "stream"
stream["name"] = "stdout" stream["name"] = "stdout"
stream["text"] = collect(Any, eachline(IOBuffer(String(str)), keep = true)) stream["text"] = collect(Any, eachline(IOBuffer(String(str)), keep = true))
@ -852,7 +873,7 @@ function execute_notebook(nb; inputfile::String, fake_source::String, softscope:
# Any explicit calls to display(...) # Any explicit calls to display(...)
for dict in display_dicts for dict in display_dicts
display_data = Dict{String,Any}() display_data = Dict{String, Any}()
display_data["output_type"] = "display_data" display_data["output_type"] = "display_data"
display_data["metadata"] = Dict() display_data["metadata"] = Dict()
display_data["data"] = split_mime(dict) display_data["data"] = split_mime(dict)
@ -864,7 +885,7 @@ function execute_notebook(nb; inputfile::String, fake_source::String, softscope:
# r should go into execute_result # r should go into execute_result
if r !== nothing if r !== nothing
execute_result = Dict{String,Any}() execute_result = Dict{String, Any}()
execute_result["output_type"] = "execute_result" execute_result["output_type"] = "execute_result"
execute_result["metadata"] = Dict() execute_result["metadata"] = Dict()
execute_result["execution_count"] = execution_count execute_result["execution_count"] = execution_count
@ -899,7 +920,7 @@ end
# TODO: Problematic to accept mime::MIME here? # TODO: Problematic to accept mime::MIME here?
function Base.display(ld::LiterateDisplay, mime::MIME, x) function Base.display(ld::LiterateDisplay, mime::MIME, x)
r = Base.invokelatest(IJulia.limitstringmime, mime, x) r = Base.invokelatest(IJulia.limitstringmime, mime, x)
display_dicts = Dict{String,Any}(string(mime) => r) display_dicts = Dict{String, Any}(string(mime) => r)
# TODO: IJulia does this part below for unknown mimes # TODO: IJulia does this part below for unknown mimes
# if istextmime(mime) # if istextmime(mime)
# display_dicts["text/plain"] = r # display_dicts["text/plain"] = r
@ -909,8 +930,10 @@ function Base.display(ld::LiterateDisplay, mime::MIME, x)
end end
# Execute a code-block in a module and capture stdout/stderr and the result # Execute a code-block in a module and capture stdout/stderr and the result
function execute_block(sb::Module, block::String; inputfile::String, fake_source::String, function execute_block(
softscope::Bool, continue_on_error::Bool) sb::Module, block::String; inputfile::String, fake_source::String,
softscope::Bool, continue_on_error::Bool
)
@debug """execute_block($sb, block) @debug """execute_block($sb, block)
``` ```
$(block) $(block)
@ -945,14 +968,16 @@ function execute_block(sb::Module, block::String; inputfile::String, fake_source
all_output = c.output * "\n\nERROR: " * sprint(showerror, err) all_output = c.output * "\n\nERROR: " * sprint(showerror, err)
return nothing, all_output, disp.data return nothing, all_output, disp.data
else else
error(""" error(
"""
$(sprint(showerror, c.value)) $(sprint(showerror, c.value))
when executing the following code block from inputfile `$(Base.contractuser(inputfile))` when executing the following code block from inputfile `$(Base.contractuser(inputfile))`
```julia ```julia
$block $block
``` ```
""") """
)
end end
end end
return c.value, c.output, disp.data return c.value, c.output, disp.data

498
test/runtests.jl

@ -23,6 +23,7 @@ function compare_chunks(chunks1, chunks2)
@test c1.continued == c2.continued @test c1.continued == c2.continued
end end
end end
return
end end
@testset "Literate.parse" begin @testset "Literate.parse" begin
@ -115,8 +116,8 @@ end
expected_chunks = Chunk[ expected_chunks = Chunk[
MDChunk(["" => "Line 1"]), MDChunk(["" => "Line 1"]),
CodeChunk(["Line 2"], false), CodeChunk(["Line 2"], false),
MDChunk(["" => "Line 3", "" => "","" => "Line 5"]), MDChunk(["" => "Line 3", "" => "", "" => "Line 5"]),
CodeChunk(["Line 6", "","Line 8"], false), CodeChunk(["Line 6", "", "Line 8"], false),
MDChunk(["" => "Line 9"]), MDChunk(["" => "Line 9"]),
MDChunk(["" => "Line 11"]), MDChunk(["" => "Line 11"]),
CodeChunk(["Line 12"], false), CodeChunk(["Line 12"], false),
@ -149,7 +150,7 @@ end
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"]), MDChunk(["" => "Line 80: Quarto Specific"]),
CodeChunk(["##| Line 81"], false) CodeChunk(["##| Line 81"], false),
] ]
parsed_chunks = Literate.parse(DefaultFlavor(), content) parsed_chunks = Literate.parse(DefaultFlavor(), content)
compare_chunks(parsed_chunks, expected_chunks) compare_chunks(parsed_chunks, expected_chunks)
@ -158,8 +159,8 @@ end
expected_chunks_quarto = Chunk[ expected_chunks_quarto = Chunk[
MDChunk(["" => "Line 1"]), MDChunk(["" => "Line 1"]),
CodeChunk(["Line 2"], false), CodeChunk(["Line 2"], false),
MDChunk(["" => "Line 3", "" => "","" => "Line 5"]), MDChunk(["" => "Line 3", "" => "", "" => "Line 5"]),
CodeChunk(["Line 6", "","Line 8"], false), CodeChunk(["Line 6", "", "Line 8"], false),
MDChunk(["" => "Line 9"]), MDChunk(["" => "Line 9"]),
MDChunk(["" => "Line 11"]), MDChunk(["" => "Line 11"]),
CodeChunk(["Line 12"], false), CodeChunk(["Line 12"], false),
@ -192,7 +193,7 @@ end
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"]), MDChunk(["" => "Line 80: Quarto Specific"]),
CodeChunk(["#| Line 81"], false) # parses correctly as code cell command CodeChunk(["#| Line 81"], false), # parses correctly as code cell command
] ]
parsed_chunks = Literate.parse(QuartoFlavor(), content) parsed_chunks = Literate.parse(QuartoFlavor(), content)
compare_chunks(parsed_chunks, expected_chunks_quarto) compare_chunks(parsed_chunks, expected_chunks_quarto)
@ -202,8 +203,8 @@ end
iows = IOBuffer() iows = IOBuffer()
for c in expected_chunks for c in expected_chunks
if isa(c, CodeChunk) if isa(c, CodeChunk)
foreach(x-> println(io, x), c.lines) foreach(x -> println(io, x), c.lines)
foreach(x-> println(iows, x, " "), c.lines) foreach(x -> println(iows, x, " "), c.lines)
else else
foreach(x -> println(io, "# ", x), c.lines) foreach(x -> println(io, "# ", x), c.lines)
foreach(x -> println(iows, "# ", x, " "), c.lines) foreach(x -> println(iows, "# ", x, " "), c.lines)
@ -218,111 +219,111 @@ end
end # testset parser end # testset parser
content = """ content = """
# # [Example](@id example-id) # # [Example](@id example-id)
# [foo](@ref), [bar](@ref bbaarr) # [foo](@ref), [bar](@ref bbaarr)
# [baz](@extref), [bax](@extref bbaaxx) # [baz](@extref), [bax](@extref bbaaxx)
x = 1 x = 1
#md # Only markdown #md # Only markdown
# Only markdown #md # Only markdown #md
#md x + 1 #md x + 1
x + 1 #md x + 1 #md
#!md # Not markdown #!md # Not markdown
# Not markdown #!md # Not markdown #!md
#!md x * 1 #!md x * 1
x * 1 #!md x * 1 #!md
#nb # Only notebook #nb # Only notebook
# Only notebook #nb # Only notebook #nb
#nb x + 2 #nb x + 2
x + 2 #nb x + 2 #nb
#!nb # Not notebook #!nb # Not notebook
# Not notebook #!nb # Not notebook #!nb
#!nb x * 2 #!nb x * 2
x * 2 #!nb x * 2 #!nb
#jl # Only script #jl # Only script
# Only script #jl # Only script #jl
#jl x + 3 #jl x + 3
x + 3 #jl x + 3 #jl
#!jl # Not script #!jl # Not script
# Not script #!jl # Not script #!jl
#!jl x * 3 #!jl x * 3
x * 3 #!jl x * 3 #!jl
#src # Source code only #src # Source code only
Source code only #src Source code only #src
## # Comment ## # Comment
## another comment ## another comment
#- #-
for i in 1:10 for i in 1:10
print(i) print(i)
# some markdown in a code block # some markdown in a code block
#+ #+
end end
# name: @__NAME__ # name: @__NAME__
# Link to repo root: @__REPO_ROOT_URL__/file.jl # Link to repo root: @__REPO_ROOT_URL__/file.jl
# Link to nbviewer: @__NBVIEWER_ROOT_URL__/file.jl # Link to nbviewer: @__NBVIEWER_ROOT_URL__/file.jl
# Link to binder: @__BINDER_ROOT_URL__/file.jl # Link to binder: @__BINDER_ROOT_URL__/file.jl
## name: @__NAME__ ## name: @__NAME__
## Link to repo root: @__REPO_ROOT_URL__/file.jl ## Link to repo root: @__REPO_ROOT_URL__/file.jl
## Link to nbviewer: @__NBVIEWER_ROOT_URL__/file.jl ## Link to nbviewer: @__NBVIEWER_ROOT_URL__/file.jl
## Link to binder: @__BINDER_ROOT_URL__/file.jl ## Link to binder: @__BINDER_ROOT_URL__/file.jl
# PLACEHOLDER1 # PLACEHOLDER1
# PLACEHOLDER2 # PLACEHOLDER2
## PLACEHOLDER3 ## PLACEHOLDER3
## PLACEHOLDER4 ## PLACEHOLDER4
# Some inline math: ``\\frac{df}{dx}``, some multiline inline math: ``y = # Some inline math: ``\\frac{df}{dx}``, some multiline inline math: ``y =
# kx + m``, and some display math: # kx + m``, and some display math:
# ```math # ```math
# \\int f(x) dx # \\int f(x) dx
# ``` # ```
#- #-
# Indented markdown # Indented markdown
for i in 1:10 for i in 1:10
# Indented markdown # Indented markdown
#+ #+
## Indented comment ## Indented comment
end end
# Some inline html
# ```@raw html
# <a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>
# ```
# Semicolon output supression
1 + 1;
# Completely hidden
hidden = 12 #hide
hidden * hidden #hide
# Partially hidden
hidden2 = 12 #hide
hidden2 * hidden2
#nb # A notebook cell with special metadata
#nb %% Meta1 {"meta": "data"}
#nb 1+1
#nb #-
#nb # A explicit code notebook cell
#nb #-
#nb %% [code]
#nb 1+2
#nb #-
#nb # %% [markdown] {"meta": "data"}
#nb # # Explicit markdown cell with metadata
# It can sometimes happen that a text editor line-wraps [a link which shouldn't
# break](@ref bbaarr)
#=
First multiline
comment
=#
#======================= # Some inline html
Second multiline comment # ```@raw html
=======================# # <a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>
""" # ```
# Semicolon output supression
1 + 1;
# Completely hidden
hidden = 12 #hide
hidden * hidden #hide
# Partially hidden
hidden2 = 12 #hide
hidden2 * hidden2
#nb # A notebook cell with special metadata
#nb %% Meta1 {"meta": "data"}
#nb 1+1
#nb #-
#nb # A explicit code notebook cell
#nb #-
#nb %% [code]
#nb 1+2
#nb #-
#nb # %% [markdown] {"meta": "data"}
#nb # # Explicit markdown cell with metadata
# It can sometimes happen that a text editor line-wraps [a link which shouldn't
# break](@ref bbaarr)
#=
First multiline
comment
=#
#=======================
Second multiline comment
=======================#
"""
const TRAVIS_ENV = Dict( const TRAVIS_ENV = Dict(
"TRAVIS_REPO_SLUG" => "fredrikekre/Literate.jl", "TRAVIS_REPO_SLUG" => "fredrikekre/Literate.jl",
@ -349,9 +350,15 @@ const GITLAB_ENV = Dict(
(k => nothing for k in keys(ACTIONS_ENV))..., (k => nothing for k in keys(ACTIONS_ENV))...,
) )
@testset "Literate.script" begin; Base.CoreLogging.with_logger(Base.CoreLogging.NullLogger()) do function with_nullogger_tempdir_cd(f)
mktempdir(@__DIR__) do sandbox Base.CoreLogging.with_logger(Base.CoreLogging.NullLogger()) do
cd(sandbox) do mktempdir(tmp -> cd(f, tmp), @__DIR__)
end
return
end
@testset "Literate.script" begin
with_nullogger_tempdir_cd() do
# write content to inputfile # write content to inputfile
inputfile = "inputfile.jl" inputfile = "inputfile.jl"
write(inputfile, content) write(inputfile, content)
@ -407,9 +414,9 @@ const GITLAB_ENV = Dict(
@test script == expected_script @test script == expected_script
# Travis with with PR preview build # Travis with with PR preview build
withenv(TRAVIS_ENV..., withenv(
"TRAVIS_TAG" => "", TRAVIS_ENV..., "TRAVIS_TAG" => "", "TRAVIS_PULL_REQUEST" => "42"
"TRAVIS_PULL_REQUEST" => "42") do ) do
Literate.script(inputfile, outdir) Literate.script(inputfile, outdir)
end end
script = read(joinpath(outdir, "inputfile.jl"), String) script = read(joinpath(outdir, "inputfile.jl"), String)
@ -418,8 +425,9 @@ const GITLAB_ENV = Dict(
@test occursin("# Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=previews/PR42/file.jl", script) @test occursin("# Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=previews/PR42/file.jl", script)
# Travis with no tag -> dev directory # Travis with no tag -> dev directory
withenv(TRAVIS_ENV..., withenv(
"TRAVIS_TAG" => "") do TRAVIS_ENV..., "TRAVIS_TAG" => ""
) do
Literate.script(inputfile, outdir) Literate.script(inputfile, outdir)
end end
script = read(joinpath(outdir, "inputfile.jl"), String) script = read(joinpath(outdir, "inputfile.jl"), String)
@ -437,9 +445,10 @@ const GITLAB_ENV = Dict(
@test occursin("# Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=v1.2.0/file.jl", script) @test occursin("# Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=v1.2.0/file.jl", script)
# GitHub Actions with PR preview build # GitHub Actions with PR preview build
withenv(ACTIONS_ENV..., withenv(
"GITHUB_EVENT_NAME" => "pull_request", ACTIONS_ENV...,
"GITHUB_REF" => "refs/pull/42/merge") do "GITHUB_EVENT_NAME" => "pull_request", "GITHUB_REF" => "refs/pull/42/merge"
) do
Literate.script(inputfile, outdir) Literate.script(inputfile, outdir)
end end
script = read(joinpath(outdir, "inputfile.jl"), String) script = read(joinpath(outdir, "inputfile.jl"), String)
@ -448,8 +457,9 @@ const GITLAB_ENV = Dict(
@test occursin("# Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=previews/PR42/file.jl", script) @test occursin("# Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=previews/PR42/file.jl", script)
# GitHub Actions without a tag -> dev directory # GitHub Actions without a tag -> dev directory
withenv(ACTIONS_ENV..., withenv(
"GITHUB_REF" => "refs/heads/master") do ACTIONS_ENV..., "GITHUB_REF" => "refs/heads/master"
) do
Literate.script(inputfile, outdir) Literate.script(inputfile, outdir)
end end
script = read(joinpath(outdir, "inputfile.jl"), String) script = read(joinpath(outdir, "inputfile.jl"), String)
@ -458,8 +468,10 @@ const GITLAB_ENV = Dict(
@test occursin("# Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl", script) @test occursin("# Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl", script)
# building under DocumentationGenerator.jl # building under DocumentationGenerator.jl
withenv("DOCUMENTATIONGENERATOR" => "true", withenv(
"DOCUMENTATIONGENERATOR_BASE_URL" => "pkg.julialang.org/docs/Literate/XPnWG/1.2.0") do "DOCUMENTATIONGENERATOR" => "true",
"DOCUMENTATIONGENERATOR_BASE_URL" => "pkg.julialang.org/docs/Literate/XPnWG/1.2.0"
) do
Literate.script(inputfile, outdir) Literate.script(inputfile, outdir)
end end
script = read(joinpath(outdir, "inputfile.jl"), String) script = read(joinpath(outdir, "inputfile.jl"), String)
@ -467,9 +479,11 @@ const GITLAB_ENV = Dict(
@test_broken occursin("https://github.com/fredrikekre/Literate.jl/blob/master/file.jl", script) @test_broken occursin("https://github.com/fredrikekre/Literate.jl/blob/master/file.jl", script)
# pre- and post-processing # pre- and post-processing
Literate.script(inputfile, outdir, Literate.script(
inputfile, outdir,
preprocess = x -> replace(x, "PLACEHOLDER3" => "3REDLOHECALP"), preprocess = x -> replace(x, "PLACEHOLDER3" => "3REDLOHECALP"),
postprocess = x -> replace(x, "PLACEHOLDER4" => "4REDLOHECALP")) postprocess = x -> replace(x, "PLACEHOLDER4" => "4REDLOHECALP")
)
script = read(joinpath(outdir, "inputfile.jl"), String) script = read(joinpath(outdir, "inputfile.jl"), String)
@test !occursin("PLACEHOLDER1", script) @test !occursin("PLACEHOLDER1", script)
@test !occursin("PLACEHOLDER2", script) @test !occursin("PLACEHOLDER2", script)
@ -497,11 +511,14 @@ const GITLAB_ENV = Dict(
""" """
# It can sometimes happen that a text editor line-wraps a link which shouldn't # It can sometimes happen that a text editor line-wraps a link which shouldn't
# break""", # break""",
script) script
)
# mdstrings # mdstrings
mdstrings_file = "inputfile_mdstrings.jl" mdstrings_file = "inputfile_mdstrings.jl"
write(mdstrings_file, """ write(
mdstrings_file,
"""
md\"\"\" md\"\"\"
# Markdown header # Markdown header
@ -516,9 +533,12 @@ const GITLAB_ENV = Dict(
comment comment
===# ===#
2 + 2 2 + 2
""") """
Literate.script(mdstrings_file, outdir, )
keep_comments = true, credit=false) Literate.script(
mdstrings_file, outdir,
keep_comments = true, credit = false
)
script = read(joinpath(outdir, mdstrings_file), String) script = read(joinpath(outdir, mdstrings_file), String)
@test strip(script) == """ @test strip(script) == """
md\"\"\" md\"\"\"
@ -535,8 +555,10 @@ const GITLAB_ENV = Dict(
# comment # comment
2 + 2""" 2 + 2"""
Literate.script(mdstrings_file, outdir, Literate.script(
keep_comments = true, mdstrings = true, credit=false) mdstrings_file, outdir,
keep_comments = true, mdstrings = true, credit = false
)
script = read(joinpath(outdir, mdstrings_file), String) script = read(joinpath(outdir, mdstrings_file), String)
@test strip(script) == """ @test strip(script) == """
# # Markdown header # # Markdown header
@ -555,16 +577,14 @@ const GITLAB_ENV = Dict(
@test_throws ArgumentError Literate.script("nonexistent.jl", outdir) @test_throws ArgumentError Literate.script("nonexistent.jl", outdir)
# default output directory # default output directory
Literate.script(inputfile; name="default-output-directory") Literate.script(inputfile; name = "default-output-directory")
@test isfile("default-output-directory.jl") @test isfile("default-output-directory.jl")
@test_throws ArgumentError Literate.script(inputfile) @test_throws ArgumentError Literate.script(inputfile)
end end
end end
end end
@testset "Literate.markdown" begin; Base.CoreLogging.with_logger(Base.CoreLogging.NullLogger()) do @testset "Literate.markdown" begin
mktempdir(@__DIR__) do sandbox with_nullogger_tempdir_cd() do
cd(sandbox) do
# write content to inputfile # write content to inputfile
inputfile = "inputfile.jl" inputfile = "inputfile.jl"
write(inputfile, content) write(inputfile, content)
@ -706,9 +726,9 @@ end end
@test markdown == expected_markdown @test markdown == expected_markdown
# Travis with PR preview build # Travis with PR preview build
withenv(TRAVIS_ENV..., withenv(
"TRAVIS_TAG" => "", TRAVIS_ENV..., "TRAVIS_TAG" => "", "TRAVIS_PULL_REQUEST" => "42"
"TRAVIS_PULL_REQUEST" => "42") do ) do
Literate.markdown(inputfile, outdir) Literate.markdown(inputfile, outdir)
end end
markdown = read(joinpath(outdir, "inputfile.md"), String) markdown = read(joinpath(outdir, "inputfile.md"), String)
@ -718,8 +738,9 @@ end end
@test occursin("EditURL = \"../inputfile.jl\"", markdown) @test occursin("EditURL = \"../inputfile.jl\"", markdown)
# Travis with no tag -> dev directory # Travis with no tag -> dev directory
withenv(TRAVIS_ENV..., withenv(
"TRAVIS_TAG" => "") do TRAVIS_ENV..., "TRAVIS_TAG" => ""
) do
Literate.markdown(inputfile, outdir) Literate.markdown(inputfile, outdir)
end end
markdown = read(joinpath(outdir, "inputfile.md"), String) markdown = read(joinpath(outdir, "inputfile.md"), String)
@ -739,9 +760,10 @@ end end
@test occursin("EditURL = \"../inputfile.jl\"", markdown) @test occursin("EditURL = \"../inputfile.jl\"", markdown)
# GitHub Actions with PR preview build # GitHub Actions with PR preview build
withenv(ACTIONS_ENV..., withenv(
"GITHUB_REF" => "refs/pull/42/merge", ACTIONS_ENV...,
"GITHUB_EVENT_NAME" => "pull_request") do "GITHUB_REF" => "refs/pull/42/merge", "GITHUB_EVENT_NAME" => "pull_request"
) do
Literate.markdown(inputfile, outdir) Literate.markdown(inputfile, outdir)
end end
markdown = read(joinpath(outdir, "inputfile.md"), String) markdown = read(joinpath(outdir, "inputfile.md"), String)
@ -751,8 +773,9 @@ end end
@test occursin("EditURL = \"../inputfile.jl\"", markdown) @test occursin("EditURL = \"../inputfile.jl\"", markdown)
# GitHub Actions without a tag -> dev directory # GitHub Actions without a tag -> dev directory
withenv(ACTIONS_ENV..., withenv(
"GITHUB_REF" => "refs/heads/master") do ACTIONS_ENV..., "GITHUB_REF" => "refs/heads/master"
) do
Literate.markdown(inputfile, outdir) Literate.markdown(inputfile, outdir)
end end
markdown = read(joinpath(outdir, "inputfile.md"), String) markdown = read(joinpath(outdir, "inputfile.md"), String)
@ -772,8 +795,10 @@ end end
@test occursin("EditURL = \"../inputfile.jl\"", markdown) @test occursin("EditURL = \"../inputfile.jl\"", markdown)
# building under DocumentationGenerator.jl # building under DocumentationGenerator.jl
withenv("DOCUMENTATIONGENERATOR" => "true", withenv(
"DOCUMENTATIONGENERATOR_BASE_URL" => "pkg.julialang.org/docs/Literate/XPnWG/1.2.0") do "DOCUMENTATIONGENERATOR" => "true",
"DOCUMENTATIONGENERATOR_BASE_URL" => "pkg.julialang.org/docs/Literate/XPnWG/1.2.0"
) do
Literate.markdown(inputfile, outdir) Literate.markdown(inputfile, outdir)
end end
markdown = read(joinpath(outdir, "inputfile.md"), String) markdown = read(joinpath(outdir, "inputfile.md"), String)
@ -781,9 +806,11 @@ end end
@test_broken occursin("https://github.com/fredrikekre/Literate.jl/blob/master/file.jl", markdown) @test_broken occursin("https://github.com/fredrikekre/Literate.jl/blob/master/file.jl", markdown)
# pre- and post-processing # pre- and post-processing
Literate.markdown(inputfile, outdir, Literate.markdown(
inputfile, outdir,
preprocess = x -> replace(replace(x, "PLACEHOLDER1" => "1REDLOHECALP"), "PLACEHOLDER3" => "3REDLOHECALP"), preprocess = x -> replace(replace(x, "PLACEHOLDER1" => "1REDLOHECALP"), "PLACEHOLDER3" => "3REDLOHECALP"),
postprocess = x -> replace(replace(x, "PLACEHOLDER2" => "2REDLOHECALP"), "PLACEHOLDER4" => "4REDLOHECALP")) postprocess = x -> replace(replace(x, "PLACEHOLDER2" => "2REDLOHECALP"), "PLACEHOLDER4" => "4REDLOHECALP")
)
markdown = read(joinpath(outdir, "inputfile.md"), String) markdown = read(joinpath(outdir, "inputfile.md"), String)
@test !occursin("PLACEHOLDER1", markdown) @test !occursin("PLACEHOLDER1", markdown)
@test !occursin("PLACEHOLDER2", markdown) @test !occursin("PLACEHOLDER2", markdown)
@ -808,7 +835,7 @@ end end
let expected_error = ArgumentError("QuartoFlavor does not support `execute = true`.") let expected_error = ArgumentError("QuartoFlavor does not support `execute = true`.")
@test_throws expected_error Literate.markdown("quarto.jl", flavor = Literate.QuartoFlavor(), execute = true) @test_throws expected_error Literate.markdown("quarto.jl", flavor = Literate.QuartoFlavor(), execute = true)
end end
Literate.markdown(inputfile, outdir, flavor = Literate.QuartoFlavor(),execute=false) Literate.markdown(inputfile, outdir, flavor = Literate.QuartoFlavor(), execute = false)
markdown = read(joinpath(outdir, "inputfile.qmd"), String) markdown = read(joinpath(outdir, "inputfile.qmd"), String)
@test occursin("```{julia}", markdown) @test occursin("```{julia}", markdown)
@test !occursin(r"`{3,}@example", markdown) @test !occursin(r"`{3,}@example", markdown)
@ -850,14 +877,15 @@ end end
# edit_commit # edit_commit
withenv(ACTIONS_ENV...) do withenv(ACTIONS_ENV...) do
Literate.markdown(inputfile, outdir; edit_commit="retsam") Literate.markdown(inputfile, outdir; edit_commit = "retsam")
end end
markdown = read(joinpath(outdir, "inputfile.md"), String) markdown = read(joinpath(outdir, "inputfile.md"), String)
@test occursin("blob/retsam/", markdown) @test occursin("blob/retsam/", markdown)
@test !occursin("blob/master/", markdown) @test !occursin("blob/master/", markdown)
# execute # execute
write(inputfile, """ write(
inputfile, """
using DisplayAs using DisplayAs
#- #-
1+1 1+1
@ -912,8 +940,9 @@ end end
(@__DIR__) == pwd() ? "cwd correct" : "cwd incorrect" (@__DIR__) == pwd() ? "cwd correct" : "cwd incorrect"
#- #-
basename(@__FILE__) basename(@__FILE__)
""") """
Literate.markdown(inputfile, outdir; execute=true) )
Literate.markdown(inputfile, outdir; execute = true)
markdown = read(joinpath(outdir, "inputfile.md"), String) markdown = read(joinpath(outdir, "inputfile.md"), String)
@test occursin("```\n2\n```", markdown) # text/plain @test occursin("```\n2\n```", markdown) # text/plain
@test occursin("```\n2×2 $(Matrix{Int}):\n 1 2\n 3 4\n```", markdown) # text/plain @test occursin("```\n2×2 $(Matrix{Int}):\n 1 2\n 3 4\n```", markdown) # text/plain
@ -938,14 +967,14 @@ end end
@test occursin("```\n\"inputfile.md\"\n```", markdown) # Correct source file (@__FILE__) @test occursin("```\n\"inputfile.md\"\n```", markdown) # Correct source file (@__FILE__)
# FranklinFlavor # FranklinFlavor
Literate.markdown(inputfile, outdir; execute=true, flavor=Literate.FranklinFlavor()) Literate.markdown(inputfile, outdir; execute = true, flavor = Literate.FranklinFlavor())
markdown = read(joinpath(outdir, "inputfile.md"), String) markdown = read(joinpath(outdir, "inputfile.md"), String)
@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 # QuartoFlavor file extension
write(inputfile, "#=\r\nhello world\n=#\r\n") write(inputfile, "#=\r\nhello world\n=#\r\n")
_, config = Literate.preprocessor(inputfile, outdir; user_kwargs=(), user_config=Dict("flavor"=>Literate.QuartoFlavor()), type=:md) _, config = Literate.preprocessor(inputfile, outdir; user_kwargs = (), user_config = Dict("flavor" => Literate.QuartoFlavor()), type = :md)
@test config["literate_ext"] == ".qmd" @test config["literate_ext"] == ".qmd"
# verify that inputfile exists # verify that inputfile exists
@ -953,16 +982,18 @@ end end
# default output directory # default output directory
@test !isfile("inputfile.md") @test !isfile("inputfile.md")
Literate.markdown(inputfile; execute=false) Literate.markdown(inputfile; execute = false)
@test isfile("inputfile.md") @test isfile("inputfile.md")
# fredrikekre/Literate.jl#165: \r\n line endings with multiline comments/mdstrings # fredrikekre/Literate.jl#165: \r\n line endings with multiline comments/mdstrings
write(inputfile, "#=\r\nhello world\r\nhej världen\r\n=#\r\n") write(inputfile, "#=\r\nhello world\r\nhej världen\r\n=#\r\n")
chunks, _ = Literate.preprocessor(inputfile, outdir; user_kwargs=(), user_config=(), type=:md) chunks, _ = Literate.preprocessor(inputfile, outdir; user_kwargs = (), user_config = (), type = :md)
@test chunks[2].lines == ["" => "hello world", "" => "hej världen"] @test chunks[2].lines == ["" => "hello world", "" => "hej världen"]
write(inputfile, "md\"\"\"\r\nhello world\r\nhej världen\r\n\"\"\"\r\n") write(inputfile, "md\"\"\"\r\nhello world\r\nhej världen\r\n\"\"\"\r\n")
chunks, _ = Literate.preprocessor(inputfile, outdir; user_kwargs=pairs((; mdstrings=true)), chunks, _ = Literate.preprocessor(
user_config=(), type=:md) inputfile, outdir; user_kwargs = pairs((; mdstrings = true)),
user_config = (), type = :md
)
@test chunks[2].lines == ["" => "hello world", "" => "hej världen"] @test chunks[2].lines == ["" => "hello world", "" => "hej världen"]
# fredrikekre/Literate.jl#168 # fredrikekre/Literate.jl#168
@ -981,8 +1012,10 @@ end end
SVG() SVG()
""", """,
) )
Literate.markdown(inputfile, relpath(outdir); execute=true, Literate.markdown(
flavor=Literate.CommonMarkFlavor()) inputfile, relpath(outdir); execute = true,
flavor = Literate.CommonMarkFlavor()
)
@test read(joinpath(outdir, "inputfile-1.svg"), String) == "issue228" @test read(joinpath(outdir, "inputfile-1.svg"), String) == "issue228"
# Softscope # Softscope
@ -996,22 +1029,20 @@ end end
println("ret = ", ret) println("ret = ", ret)
""" """
) )
Literate.markdown(inputfile, outdir; execute=true, softscope=true) Literate.markdown(inputfile, outdir; execute = true, softscope = true)
@test occursin("ret = 55", read(joinpath(outdir, "inputfile.md"), String)) @test occursin("ret = 55", read(joinpath(outdir, "inputfile.md"), String))
## Disabled softscope ## Disabled softscope
try try
Literate.markdown(inputfile, outdir; execute=true, softscope=false) Literate.markdown(inputfile, outdir; execute = true, softscope = false)
error("unreachable") error("unreachable")
catch err catch err
@test occursin(r"`?ret`? not defined", sprint(Base.showerror, err)) @test occursin(r"`?ret`? not defined", sprint(Base.showerror, err))
end end
end # cd(sandbox) end
end # mktemp end
end end
@testset "Literate.notebook" begin; Base.CoreLogging.with_logger(Base.CoreLogging.NullLogger()) do @testset "Literate.notebook" begin
mktempdir(@__DIR__) do sandbox with_nullogger_tempdir_cd() do
cd(sandbox) do
# write content to inputfile # write content to inputfile
inputfile = "inputfile.jl" inputfile = "inputfile.jl"
write(inputfile, content) write(inputfile, content)
@ -1021,11 +1052,11 @@ end end
withenv(TRAVIS_ENV...) do withenv(TRAVIS_ENV...) do
Literate.notebook(inputfile, outdir, execute = false) Literate.notebook(inputfile, outdir, execute = false)
end end
expected_cells = rstrip.(( expected_cells = rstrip.(
[
""" """
"cells": [ "cells": [
""", """,
""" """
"source": [ "source": [
"# Example\\n", "# Example\\n",
@ -1033,48 +1064,41 @@ end end
"baz, bax" "baz, bax"
] ]
""", """,
""" """
"source": [ "source": [
"x = 1" "x = 1"
] ]
""", """,
""" """
"source": [ "source": [
"Not markdown\\n", "Not markdown\\n",
"Not markdown" "Not markdown"
], ],
""", """,
""" """
"source": [ "source": [
"x * 1\\n", "x * 1\\n",
"x * 1" "x * 1"
], ],
""", """,
""" """
"source": [ "source": [
"Only notebook\\n", "Only notebook\\n",
"Only notebook" "Only notebook"
] ]
""", """,
""" """
"source": [ "source": [
"x + 2\\n", "x + 2\\n",
"x + 2" "x + 2"
] ]
""", """,
""" """
"source": [ "source": [
"Not script\\n", "Not script\\n",
"Not script" "Not script"
], ],
""", """,
""" """
"source": [ "source": [
"x * 3\\n", "x * 3\\n",
@ -1083,7 +1107,6 @@ end end
"# another comment" "# another comment"
], ],
""", """,
""" """
"source": [ "source": [
"for i in 1:10\\n", "for i in 1:10\\n",
@ -1092,7 +1115,6 @@ end end
"end" "end"
] ]
""", """,
""" """
"source": [ "source": [
"name: inputfile\\n", "name: inputfile\\n",
@ -1101,7 +1123,6 @@ end end
"Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=v1.2.0/file.jl" "Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=v1.2.0/file.jl"
] ]
""", """,
""" """
"source": [ "source": [
"# name: inputfile\\n", "# name: inputfile\\n",
@ -1110,21 +1131,18 @@ end end
"# Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=v1.2.0/file.jl" "# Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=v1.2.0/file.jl"
] ]
""", """,
""" """
"source": [ "source": [
"PLACEHOLDER1\\n", "PLACEHOLDER1\\n",
"PLACEHOLDER2" "PLACEHOLDER2"
] ]
""", """,
""" """
"source": [ "source": [
"# PLACEHOLDER3\\n", "# PLACEHOLDER3\\n",
"# PLACEHOLDER4" "# PLACEHOLDER4"
] ]
""", """,
""" """
"source": [ "source": [
"Some inline math: \$\\\\frac{df}{dx}\$, some multiline inline math: \$y =\\n", "Some inline math: \$\\\\frac{df}{dx}\$, some multiline inline math: \$y =\\n",
@ -1134,13 +1152,11 @@ end end
"\$\$" "\$\$"
] ]
""", """,
""" """
"source": [ "source": [
"Indented markdown" "Indented markdown"
] ]
""", """,
""" """
"source": [ "source": [
"for i in 1:10\\n", "for i in 1:10\\n",
@ -1149,7 +1165,6 @@ end end
"end" "end"
] ]
""", """,
""" """
"source": [ "source": [
"Some inline html\\n", "Some inline html\\n",
@ -1157,27 +1172,26 @@ end end
" <a href=\\"https://github.com/fredrikekre/Literate.jl\\">Literate.jl</a>" " <a href=\\"https://github.com/fredrikekre/Literate.jl\\">Literate.jl</a>"
] ]
""", """,
""" """
"metadata": { "metadata": {
"meta": "data" "meta": "data"
} }
""", """,
""" """
"source": [ "source": [
"First multiline\\n", "First multiline\\n",
"comment" "comment"
] ]
""", """,
""" """
"source": [ "source": [
"---\\n", "---\\n",
"\\n", "\\n",
"*This notebook was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*" "*This notebook was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*"
] ]
""")) """,
]
)
notebook = read(joinpath(outdir, "inputfile.ipynb"), String) notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@ -1188,16 +1202,19 @@ end end
lastidx = nextind(notebook, last(idx)) lastidx = nextind(notebook, last(idx))
end end
# test some of the required metadata # test some of the required metadata
for metadata in (" \"nbformat\": ", " \"nbformat_minor\": ", " \"metadata\": {", " \"language_info\": {", for metadata in (
" \"nbformat\": ", " \"nbformat_minor\": ", " \"metadata\": {", " \"language_info\": {",
" \"file_extension\": \".jl\"", " \"mimetype\": \"application/julia\"", " \"file_extension\": \".jl\"", " \"mimetype\": \"application/julia\"",
" \"name\": \"julia\"", " \"version\": ", " \"kernelspec\": {", " \"name\": \"julia\"", " \"version\": ", " \"kernelspec\": {",
" \"name\": \"julia-", " \"display_name\": \"Julia ", " \"language\": \"julia\"") " \"name\": \"julia-", " \"display_name\": \"Julia ", " \"language\": \"julia\"",
)
@test occursin(metadata, notebook) @test occursin(metadata, notebook)
end end
# no tag -> latest directory # no tag -> latest directory
withenv(TRAVIS_ENV..., withenv(
"TRAVIS_TAG" => "") do TRAVIS_ENV..., "TRAVIS_TAG" => ""
) do
Literate.notebook(inputfile, outdir, execute = false) Literate.notebook(inputfile, outdir, execute = false)
end end
notebook = read(joinpath(outdir, "inputfile.ipynb"), String) notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@ -1211,25 +1228,29 @@ end end
@test occursin("fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/", notebook) @test occursin("fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/", notebook)
# GitHub Actions with PR preview build # GitHub Actions with PR preview build
withenv(ACTIONS_ENV..., withenv(
"GITHUB_REF" => "refs/pull/42/merge", ACTIONS_ENV...,
"GITHUB_EVENT_NAME" => "pull_request") do "GITHUB_REF" => "refs/pull/42/merge", "GITHUB_EVENT_NAME" => "pull_request"
) do
Literate.notebook(inputfile, outdir, execute = false) Literate.notebook(inputfile, outdir, execute = false)
end end
notebook = read(joinpath(outdir, "inputfile.ipynb"), String) notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@test occursin("fredrikekre/Literate.jl/blob/gh-pages/previews/PR42/", notebook) @test occursin("fredrikekre/Literate.jl/blob/gh-pages/previews/PR42/", notebook)
# GitHub Actions without a tag # GitHub Actions without a tag
withenv(ACTIONS_ENV..., withenv(
"GITHUB_REF" => "refs/heads/master") do ACTIONS_ENV..., "GITHUB_REF" => "refs/heads/master"
) do
Literate.notebook(inputfile, outdir, execute = false) Literate.notebook(inputfile, outdir, execute = false)
end end
notebook = read(joinpath(outdir, "inputfile.ipynb"), String) notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@test occursin("fredrikekre/Literate.jl/blob/gh-pages/dev/", notebook) @test occursin("fredrikekre/Literate.jl/blob/gh-pages/dev/", notebook)
# building under DocumentationGenerator.jl # building under DocumentationGenerator.jl
withenv("DOCUMENTATIONGENERATOR" => "true", withenv(
"DOCUMENTATIONGENERATOR_BASE_URL" => "pkg.julialang.org/docs/Literate/XPnWG/1.2.0") do "DOCUMENTATIONGENERATOR" => "true",
"DOCUMENTATIONGENERATOR_BASE_URL" => "pkg.julialang.org/docs/Literate/XPnWG/1.2.0"
) do
Literate.notebook(inputfile, outdir, execute = false) Literate.notebook(inputfile, outdir, execute = false)
end end
notebook = read(joinpath(outdir, "inputfile.ipynb"), String) notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@ -1246,9 +1267,11 @@ end end
end end
return nb return nb
end end
Literate.notebook(inputfile, outdir, execute = false, Literate.notebook(
inputfile, outdir, execute = false,
preprocess = x -> replace(replace(x, "PLACEHOLDER1" => "1REDLOHECALP"), "PLACEHOLDER3" => "3REDLOHECALP"), preprocess = x -> replace(replace(x, "PLACEHOLDER1" => "1REDLOHECALP"), "PLACEHOLDER3" => "3REDLOHECALP"),
postprocess = post) postprocess = post
)
notebook = read(joinpath(outdir, "inputfile.ipynb"), String) notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@test !occursin("PLACEHOLDER1", notebook) @test !occursin("PLACEHOLDER1", notebook)
@test !occursin("PLACEHOLDER2", notebook) @test !occursin("PLACEHOLDER2", notebook)
@ -1277,22 +1300,23 @@ end end
# execute = true # execute = true
Literate.notebook(inputfile, outdir) Literate.notebook(inputfile, outdir)
expected_outputs = rstrip.(( expected_outputs = rstrip.(
[
""" """
"cells": [ "cells": [
""", """,
""" """
"data": { "data": {
"text/plain": "3" "text/plain": "3"
}, },
""", """,
""" """
"text": [ "text": [
"12345678910" "12345678910"
] ]
""")) """,
]
)
notebook = read(joinpath(outdir, "inputfile.ipynb"), String) notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@ -1321,12 +1345,14 @@ end end
# test error when executing notebook # test error when executing notebook
write(inputfile, "for i in 1:10\n println(i)") write(inputfile, "for i in 1:10\n println(i)")
r = @test_logs((:error, r"error when executing notebook based on input file: "), match_mode=:any, r = @test_logs(
(:error, r"error when executing notebook based on input file: "), match_mode = :any,
try try
Literate.notebook(inputfile, outdir) Literate.notebook(inputfile, outdir)
catch err catch err
err err
end) end
)
@test isa(r, ErrorException) @test isa(r, ErrorException)
@test occursin("when executing the following code block from inputfile ", r.msg) @test occursin("when executing the following code block from inputfile ", r.msg)
@test occursin(inputfile, r.msg) @test occursin(inputfile, r.msg)
@ -1336,11 +1362,13 @@ end end
# default output directory # default output directory
@test !isfile("inputfile.ipynb") @test !isfile("inputfile.ipynb")
Literate.notebook(inputfile; execute=false) Literate.notebook(inputfile; execute = false)
@test isfile("inputfile.ipynb") @test isfile("inputfile.ipynb")
# world time problem with `IJulia.display_dict` # world time problem with `IJulia.display_dict`
write(inputfile, """ write(
inputfile,
"""
struct VegaLiteRenderable end struct VegaLiteRenderable end
Base.show(io::IO, ::MIME"application/vnd.vegalite.v2+json", ::VegaLiteRenderable) = Base.show(io::IO, ::MIME"application/vnd.vegalite.v2+json", ::VegaLiteRenderable) =
write(io, \"\"\" write(io, \"\"\"
@ -1348,7 +1376,8 @@ end end
\"\"\") \"\"\")
Base.Multimedia.istextmime(::MIME{Symbol("application/vnd.vegalite.v2+json")}) = true Base.Multimedia.istextmime(::MIME{Symbol("application/vnd.vegalite.v2+json")}) = true
VegaLiteRenderable() VegaLiteRenderable()
""") """
)
Literate.notebook(inputfile, outdir) Literate.notebook(inputfile, outdir)
notebook = read(joinpath(outdir, "inputfile.ipynb"), String) notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@test occursin("\"application/vnd.vegalite.v2+json\":", notebook) @test occursin("\"application/vnd.vegalite.v2+json\":", notebook)
@ -1450,14 +1479,13 @@ end end
@test occursin("ret = 55", read(joinpath(outdir, "inputfile2.ipynb"), String)) @test occursin("ret = 55", read(joinpath(outdir, "inputfile2.ipynb"), String))
## Disabled softscope ## Disabled softscope
try try
Literate.notebook(new_inputfile, outdir; softscope=false) Literate.notebook(new_inputfile, outdir; softscope = false)
error("unreachable") error("unreachable")
catch err catch err
@test occursin(r"`?ret`? not defined", sprint(Base.showerror, err)) @test occursin(r"`?ret`? not defined", sprint(Base.showerror, err))
end end
end # cd(sandbox) end
end # mktempdir end
end end
@testset "continue_on_error=true" begin @testset "continue_on_error=true" begin
input_with_error = input_with_error =
@ -1529,26 +1557,25 @@ end
end end
end end
@testset "Configuration" begin; Base.CoreLogging.with_logger(Base.CoreLogging.NullLogger()) do @testset "Configuration" begin
mktempdir(@__DIR__) do sandbox with_nullogger_tempdir_cd() do
cd(sandbox) do
# write content to inputfile # write content to inputfile
inputfile = "inputfile.jl" inputfile = "inputfile.jl"
write(inputfile, content) write(inputfile, content)
outdir = mktempdir(pwd()) outdir = mktempdir(pwd())
config=Dict( config = Dict(
"repo_root_url" => "www.example1.com", "repo_root_url" => "www.example1.com",
"nbviewer_root_url" => "www.example2.com", "nbviewer_root_url" => "www.example2.com",
"binder_root_url" => "www.example3.com", "binder_root_url" => "www.example3.com",
) )
# Overwriting of URLs # Overwriting of URLs
withenv("TRAVIS_REPO_SLUG" => "fredrikekre/Literate.jl", withenv(
"TRAVIS_TAG" => "", "TRAVIS_REPO_SLUG" => "fredrikekre/Literate.jl", "TRAVIS_TAG" => "",
"TRAVIS_PULL_REQUEST" => "false", "TRAVIS_PULL_REQUEST" => "false", "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true"
"HAS_JOSH_K_SEAL_OF_APPROVAL" => "true") do ) do
Literate.script(inputfile, outdir; config=config) Literate.script(inputfile, outdir; config = config)
end end
script = read(joinpath(outdir, "inputfile.jl"), String) script = read(joinpath(outdir, "inputfile.jl"), String)
@test occursin("Link to repo root: www.example1.com/file.jl", script) @test occursin("Link to repo root: www.example1.com/file.jl", script)
@ -1556,7 +1583,7 @@ end
@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 # Test pick_codefence function
default_codefence=pick_codefence(Literate.DefaultFlavor(), true, "testname") default_codefence = pick_codefence(Literate.DefaultFlavor(), true, "testname")
@test default_codefence == ("````julia" => "````") @test default_codefence == ("````julia" => "````")
@test default_codefence == pick_codefence(Literate.FranklinFlavor(), true, "testname") @test default_codefence == pick_codefence(Literate.FranklinFlavor(), true, "testname")
@test default_codefence == pick_codefence(Literate.DocumenterFlavor(), true, "testname") @test default_codefence == pick_codefence(Literate.DocumenterFlavor(), true, "testname")
@ -1566,13 +1593,12 @@ end
@test ("```{julia}" => "```") == pick_codefence(Literate.QuartoFlavor(), false, "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)
@test cfg["execute"] @test cfg["execute"]
@test cfg["codefence"] == ("````julia" => "````") @test cfg["codefence"] == ("````julia" => "````")
cfg = create(; type=:md, execute=false) cfg = create(; type = :md, execute = false)
@test !cfg["execute"] @test !cfg["execute"]
@test cfg["codefence"] == ("````@example inputfile" => "````") @test cfg["codefence"] == ("````@example inputfile" => "````")
end end
end end
end end

Loading…
Cancel
Save