@ -293,7 +293,8 @@ const GITLAB_ENV = Dict(
@@ -293,7 +293,8 @@ const GITLAB_ENV = Dict(
( k => nothing for k in keys ( TRAVIS_ENV ) ) ... ,
( k => nothing for k in keys ( ACTIONS_ENV ) ) ... ,
)
@testset " Literate.script " begin ; Base . CoreLogging . with_logger ( Base . CoreLogging . NullLogger ( ) ) do
@testset " Literate.script " begin
Base . CoreLogging . with_logger ( Base . CoreLogging . NullLogger ( ) ) do
mktempdir ( @__DIR__ ) do sandbox
cd ( sandbox ) do
# write content to inputfile
@ -353,69 +354,123 @@ const GITLAB_ENV = Dict(
@@ -353,69 +354,123 @@ const GITLAB_ENV = Dict(
@test script == expected_script
# Travis with with PR preview build
withenv ( TRAVIS_ENV ... ,
" TRAVIS_TAG " => " " ,
" TRAVIS_PULL_REQUEST " => " 42 " ) do
withenv ( TRAVIS_ENV ... , " TRAVIS_TAG " => " " , " TRAVIS_PULL_REQUEST " => " 42 " ) do
Literate . script ( inputfile , outdir )
end
script = read ( joinpath ( outdir , " inputfile.jl " ) , String )
@test occursin ( " # Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " , script )
@test occursin ( " # Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/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 )
@test occursin (
" # Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " ,
script ,
)
@test occursin (
" # Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/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
withenv ( TRAVIS_ENV ... ,
" TRAVIS_TAG " => " " ) do
withenv ( TRAVIS_ENV ... , " TRAVIS_TAG " => " " ) do
Literate . script ( inputfile , outdir )
end
script = read ( joinpath ( outdir , " inputfile.jl " ) , String )
@test occursin ( " # Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " , script )
@test occursin ( " # Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/dev/file.jl " , script )
@test occursin ( " # Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl " , script )
@test occursin (
" # Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " ,
script ,
)
@test occursin (
" # Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/dev/file.jl " ,
script ,
)
@test occursin (
" # Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl " ,
script ,
)
# GitHub Actions with a tag
withenv ( ACTIONS_ENV ... ) do
Literate . script ( inputfile , outdir )
end
script = read ( joinpath ( outdir , " inputfile.jl " ) , String )
@test occursin ( " # Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " , script )
@test occursin ( " # Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/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 )
@test occursin (
" # Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " ,
script ,
)
@test occursin (
" # Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/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
withenv ( ACTIONS_ENV ... ,
withenv (
ACTIONS_ENV ... ,
" GITHUB_EVENT_NAME " => " pull_request " ,
" GITHUB_REF " => " refs/pull/42/merge " ) do
" GITHUB_REF " => " refs/pull/42/merge " ,
) do
Literate . script ( inputfile , outdir )
end
script = read ( joinpath ( outdir , " inputfile.jl " ) , String )
@test occursin ( " # Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " , script )
@test occursin ( " # Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/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 )
@test occursin (
" # Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " ,
script ,
)
@test occursin (
" # Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/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
withenv ( ACTIONS_ENV ... ,
" GITHUB_REF " => " refs/heads/master " ) do
withenv ( ACTIONS_ENV ... , " GITHUB_REF " => " refs/heads/master " ) do
Literate . script ( inputfile , outdir )
end
script = read ( joinpath ( outdir , " inputfile.jl " ) , String )
@test occursin ( " # Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " , script )
@test occursin ( " # Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/dev/file.jl " , script )
@test occursin ( " # Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl " , script )
@test occursin (
" # Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " ,
script ,
)
@test occursin (
" # Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/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
withenv ( " DOCUMENTATIONGENERATOR " => " true " ,
" DOCUMENTATIONGENERATOR_BASE_URL " => " pkg.julialang.org/docs/Literate/XPnWG/1.2.0 " ) do
withenv (
" DOCUMENTATIONGENERATOR " => " true " ,
" DOCUMENTATIONGENERATOR_BASE_URL " => " pkg.julialang.org/docs/Literate/XPnWG/1.2.0 " ,
) do
Literate . script ( inputfile , outdir )
end
script = read ( joinpath ( outdir , " inputfile.jl " ) , String )
@test occursin ( " jupyter.org/urls/pkg.julialang.org/docs/Literate/XPnWG/1.2.0/file.jl " , script )
@test_broken occursin ( " https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " , script )
@test occursin (
" jupyter.org/urls/pkg.julialang.org/docs/Literate/XPnWG/1.2.0/file.jl " ,
script ,
)
@test_broken occursin (
" https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " ,
script ,
)
# pre- and post-processing
Literate . script ( inputfile , outdir ,
Literate . script (
inputfile ,
outdir ,
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 )
@test ! occursin ( " PLACEHOLDER1 " , script )
@test ! occursin ( " PLACEHOLDER2 " , script )
@ -442,7 +497,9 @@ const GITLAB_ENV = Dict(
@@ -442,7 +497,9 @@ const GITLAB_ENV = Dict(
# mdstrings
mdstrings_file = " inputfile_mdstrings.jl "
write ( mdstrings_file , """
write (
mdstrings_file ,
"""
md \ " \" \"
# Markdown header
@ -457,9 +514,14 @@ const GITLAB_ENV = Dict(
@@ -457,9 +514,14 @@ const GITLAB_ENV = Dict(
comment
=== #
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 )
@test strip ( script ) == """
md \ " \" \"
@ -476,8 +538,13 @@ const GITLAB_ENV = Dict(
@@ -476,8 +538,13 @@ const GITLAB_ENV = Dict(
# comment
2 + 2 """
Literate . script ( mdstrings_file , outdir ,
keep_comments = true , mdstrings = true , credit = false )
Literate . script (
mdstrings_file ,
outdir ,
keep_comments = true ,
mdstrings = true ,
credit = false ,
)
script = read ( joinpath ( outdir , mdstrings_file ) , String )
@test strip ( script ) == """
# # Markdown header
@ -501,9 +568,11 @@ const GITLAB_ENV = Dict(
@@ -501,9 +568,11 @@ const GITLAB_ENV = Dict(
@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
Base . CoreLogging . with_logger ( Base . CoreLogging . NullLogger ( ) ) do
mktempdir ( @__DIR__ ) do sandbox
cd ( sandbox ) do
# write content to inputfile
@ -639,84 +708,171 @@ end end
@@ -639,84 +708,171 @@ end end
@test markdown == expected_markdown
# Travis with PR preview build
withenv ( TRAVIS_ENV ... ,
" TRAVIS_TAG " => " " ,
" TRAVIS_PULL_REQUEST " => " 42 " ) do
withenv ( TRAVIS_ENV ... , " TRAVIS_TAG " => " " , " TRAVIS_PULL_REQUEST " => " 42 " ) do
Literate . markdown ( inputfile , outdir )
end
markdown = read ( joinpath ( outdir , " inputfile.md " ) , String )
@test occursin ( " Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " , markdown )
@test occursin ( " Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/previews/PR42/file.jl " , markdown )
@test occursin ( " Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=previews/PR42/file.jl " , markdown )
@test occursin ( " EditURL = \" https://github.com/fredrikekre/Literate.jl/blob/master/test/ $ ( basename ( sandbox ) ) /inputfile.jl \" " , markdown )
@test occursin (
" Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " ,
markdown ,
)
@test occursin (
" Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/previews/PR42/file.jl " ,
markdown ,
)
@test occursin (
" Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=previews/PR42/file.jl " ,
markdown ,
)
@test occursin (
" EditURL = \" https://github.com/fredrikekre/Literate.jl/blob/master/test/ $ ( basename ( sandbox ) ) /inputfile.jl \" " ,
markdown ,
)
# Travis with no tag -> dev directory
withenv ( TRAVIS_ENV ... ,
" TRAVIS_TAG " => " " ) do
withenv ( TRAVIS_ENV ... , " TRAVIS_TAG " => " " ) do
Literate . markdown ( inputfile , outdir )
end
markdown = read ( joinpath ( outdir , " inputfile.md " ) , String )
@test occursin ( " Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " , markdown )
@test occursin ( " Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/dev/file.jl " , markdown )
@test occursin ( " Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl " , markdown )
@test occursin ( " EditURL = \" https://github.com/fredrikekre/Literate.jl/blob/master/test/ $ ( basename ( sandbox ) ) /inputfile.jl \" " , markdown )
@test occursin (
" Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " ,
markdown ,
)
@test occursin (
" Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/dev/file.jl " ,
markdown ,
)
@test occursin (
" Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl " ,
markdown ,
)
@test occursin (
" EditURL = \" https://github.com/fredrikekre/Literate.jl/blob/master/test/ $ ( basename ( sandbox ) ) /inputfile.jl \" " ,
markdown ,
)
# GitHub Actions with a tag
withenv ( ACTIONS_ENV ... ) do
Literate . markdown ( inputfile , outdir )
end
markdown = read ( joinpath ( outdir , " inputfile.md " ) , String )
@test occursin ( " Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " , markdown )
@test occursin ( " Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/file.jl " , markdown )
@test occursin ( " Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=v1.2.0/file.jl " , markdown )
@test occursin ( " EditURL = \" https://github.com/fredrikekre/Literate.jl/blob/master/test/ $ ( basename ( sandbox ) ) /inputfile.jl \" " , markdown )
@test occursin (
" Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " ,
markdown ,
)
@test occursin (
" Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/file.jl " ,
markdown ,
)
@test occursin (
" Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=v1.2.0/file.jl " ,
markdown ,
)
@test occursin (
" EditURL = \" https://github.com/fredrikekre/Literate.jl/blob/master/test/ $ ( basename ( sandbox ) ) /inputfile.jl \" " ,
markdown ,
)
# GitHub Actions with PR preview build
withenv ( ACTIONS_ENV ... ,
withenv (
ACTIONS_ENV ... ,
" GITHUB_REF " => " refs/pull/42/merge " ,
" GITHUB_EVENT_NAME " => " pull_request " ) do
" GITHUB_EVENT_NAME " => " pull_request " ,
) do
Literate . markdown ( inputfile , outdir )
end
markdown = read ( joinpath ( outdir , " inputfile.md " ) , String )
@test occursin ( " Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " , markdown )
@test occursin ( " Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/previews/PR42/file.jl " , markdown )
@test occursin ( " Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=previews/PR42/file.jl " , markdown )
@test occursin ( " EditURL = \" https://github.com/fredrikekre/Literate.jl/blob/master/test/ $ ( basename ( sandbox ) ) /inputfile.jl \" " , markdown )
@test occursin (
" Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " ,
markdown ,
)
@test occursin (
" Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/previews/PR42/file.jl " ,
markdown ,
)
@test occursin (
" Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=previews/PR42/file.jl " ,
markdown ,
)
@test occursin (
" EditURL = \" https://github.com/fredrikekre/Literate.jl/blob/master/test/ $ ( basename ( sandbox ) ) /inputfile.jl \" " ,
markdown ,
)
# GitHub Actions without a tag -> dev directory
withenv ( ACTIONS_ENV ... ,
" GITHUB_REF " => " refs/heads/master " ) do
withenv ( ACTIONS_ENV ... , " GITHUB_REF " => " refs/heads/master " ) do
Literate . markdown ( inputfile , outdir )
end
markdown = read ( joinpath ( outdir , " inputfile.md " ) , String )
@test occursin ( " Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " , markdown )
@test occursin ( " Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/dev/file.jl " , markdown )
@test occursin ( " Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl " , markdown )
@test occursin ( " EditURL = \" https://github.com/fredrikekre/Literate.jl/blob/master/test/ $ ( basename ( sandbox ) ) /inputfile.jl \" " , markdown )
@test occursin (
" Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " ,
markdown ,
)
@test occursin (
" Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/dev/file.jl " ,
markdown ,
)
@test occursin (
" Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl " ,
markdown ,
)
@test occursin (
" EditURL = \" https://github.com/fredrikekre/Literate.jl/blob/master/test/ $ ( basename ( sandbox ) ) /inputfile.jl \" " ,
markdown ,
)
# GitLab CI with GitLab Pages
withenv ( GITLAB_ENV ... ) do
Literate . markdown ( inputfile , outdir )
end
markdown = read ( joinpath ( outdir , " inputfile.md " ) , String )
@test occursin ( " Link to repo root: https://gitlab.com/fredrikekre/Literate.jl/blob/master/file.jl " , markdown )
@test occursin ( " Link to nbviewer: https://nbviewer.jupyter.org/urls/fredrikekre.gitlab.io/Literate.jl/file.jl " , markdown )
@test_broken occursin ( " Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl " , markdown )
@test occursin ( " EditURL = \" https://gitlab.com/fredrikekre/Literate.jl/blob/master/test/ $ ( basename ( sandbox ) ) /inputfile.jl \" " , markdown )
@test occursin (
" Link to repo root: https://gitlab.com/fredrikekre/Literate.jl/blob/master/file.jl " ,
markdown ,
)
@test occursin (
" Link to nbviewer: https://nbviewer.jupyter.org/urls/fredrikekre.gitlab.io/Literate.jl/file.jl " ,
markdown ,
)
@test_broken occursin (
" Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl " ,
markdown ,
)
@test occursin (
" EditURL = \" https://gitlab.com/fredrikekre/Literate.jl/blob/master/test/ $ ( basename ( sandbox ) ) /inputfile.jl \" " ,
markdown ,
)
# building under DocumentationGenerator.jl
withenv ( " DOCUMENTATIONGENERATOR " => " true " ,
" DOCUMENTATIONGENERATOR_BASE_URL " => " pkg.julialang.org/docs/Literate/XPnWG/1.2.0 " ) do
withenv (
" DOCUMENTATIONGENERATOR " => " true " ,
" DOCUMENTATIONGENERATOR_BASE_URL " => " pkg.julialang.org/docs/Literate/XPnWG/1.2.0 " ,
) do
Literate . markdown ( inputfile , outdir )
end
markdown = read ( joinpath ( outdir , " inputfile.md " ) , String )
@test occursin ( " jupyter.org/urls/pkg.julialang.org/docs/Literate/XPnWG/1.2.0/file.jl " , markdown )
@test_broken occursin ( " https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " , markdown )
@test occursin (
" jupyter.org/urls/pkg.julialang.org/docs/Literate/XPnWG/1.2.0/file.jl " ,
markdown ,
)
@test_broken occursin (
" https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " ,
markdown ,
)
# pre- and post-processing
Literate . markdown ( inputfile , outdir ,
preprocess = x -> replace ( replace ( x , " PLACEHOLDER1 " => " 1REDLOHECALP " ) , " PLACEHOLDER3 " => " 3REDLOHECALP " ) ,
postprocess = x -> replace ( replace ( x , " PLACEHOLDER2 " => " 2REDLOHECALP " ) , " PLACEHOLDER4 " => " 4REDLOHECALP " ) )
Literate . markdown (
inputfile ,
outdir ,
preprocess = x -> replace (
replace ( x , " PLACEHOLDER1 " => " 1REDLOHECALP " ) ,
" PLACEHOLDER3 " => " 3REDLOHECALP " ,
) ,
postprocess = x -> replace (
replace ( x , " PLACEHOLDER2 " => " 2REDLOHECALP " ) ,
" PLACEHOLDER4 " => " 4REDLOHECALP " ,
) ,
)
markdown = read ( joinpath ( outdir , " inputfile.md " ) , String )
@test ! occursin ( " PLACEHOLDER1 " , markdown )
@test ! occursin ( " PLACEHOLDER2 " , markdown )
@ -738,10 +894,21 @@ end end
@@ -738,10 +894,21 @@ end end
# flavor = QuartoFlavor()
# execution of Quarto markdown is not allowed
let expected_error = ErrorException ( " QuartoFlavor does not support argument execute=true! " )
@test_throws expected_error Literate . markdown ( " quarto.jl " , flavor = Literate . QuartoFlavor ( ) , execute = true )
let expected_error = ErrorException (
" QuartoFlavor does not support argument 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 )
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 )
@ -790,7 +957,9 @@ end end
@@ -790,7 +957,9 @@ end end
@test ! occursin ( " blob/master/ " , markdown )
# execute
write ( inputfile , """
write (
inputfile ,
"""
using DisplayAs
#-
1 + 1
@ -845,7 +1014,8 @@ end end
@@ -845,7 +1014,8 @@ end end
( @__DIR__ ) == pwd ( ) ? " cwd correct " : " cwd incorrect "
#-
basename ( @__FILE__ )
""" )
""" ,
)
Literate . markdown ( inputfile , outdir ; execute = true )
markdown = read ( joinpath ( outdir , " inputfile.md " ) , String )
@test occursin ( " ``` \n 2 \n ``` " , markdown ) # text/plain
@ -871,14 +1041,25 @@ end end
@@ -871,14 +1041,25 @@ end end
@test occursin ( " ``` \n \" inputfile.md \" \n ``` " , markdown ) # Correct source file (@__FILE__)
# 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 )
@test occursin ( " # MD " , markdown ) # text/markdown
@test occursin ( " ~~~ \n <h1>MD</h1> \n ~~~ " , markdown ) # text/html
# QuartoFlavor file extension
write ( inputfile , " #= \r \n hello 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 "
# verify that inputfile exists
@ -891,23 +1072,39 @@ end end
@@ -891,23 +1072,39 @@ end end
# fredrikekre/Literate.jl#165: \r\n line endings with multiline comments/mdstrings
write ( inputfile , " #= \r \n hello world \r \n hej 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 " ]
write ( inputfile , " md \" \" \" \r \n hello world \r \n hej världen \r \n \" \" \" \r \n " )
chunks , _ = Literate . preprocessor ( inputfile , outdir ; user_kwargs = pairs ( ( ; mdstrings = true ) ) ,
user_config = ( ) , type = :md )
chunks , _ = Literate . preprocessor (
inputfile ,
outdir ;
user_kwargs = pairs ( ( ; mdstrings = true ) ) ,
user_config = ( ) ,
type = :md ,
)
@test chunks [ 2 ] . lines == [ " " => " hello world " , " " => " hej världen " ]
# fredrikekre/Literate.jl#168
f = " file with space.jl "
write ( f , " 1 + 1 " )
Literate . markdown ( f , outdir )
@test occursin ( " file_with_space " , read ( joinpath ( outdir , " file with space.md " ) , String ) )
@test occursin (
" file_with_space " ,
read ( joinpath ( outdir , " file with space.md " ) , String ) ,
)
end
end
end
end
end end
@testset " Literate.notebook " begin ; Base . CoreLogging . with_logger ( Base . CoreLogging . NullLogger ( ) ) do
@testset " Literate.notebook " begin
Base . CoreLogging . with_logger ( Base . CoreLogging . NullLogger ( ) ) do
mktempdir ( @__DIR__ ) do sandbox
cd ( sandbox ) do
# write content to inputfile
@ -919,59 +1116,52 @@ end end
@@ -919,59 +1116,52 @@ end end
withenv ( TRAVIS_ENV ... ) do
Literate . notebook ( inputfile , outdir , execute = false )
end
expected_cells = rstrip . ( (
expected_cells =
rstrip . ( (
"""
" cells " : [
""" ,
"""
" source " : [
" # Example \\ n " ,
" foo, bar "
]
""" ,
"""
" source " : [
" x = 1 "
]
""" ,
"""
" source " : [
" Not markdown \\ n " ,
" Not markdown "
] ,
""" ,
"""
" source " : [
" x * 1 \\ n " ,
" x * 1 "
] ,
""" ,
"""
" source " : [
" Only notebook \\ n " ,
" Only notebook "
]
""" ,
"""
" source " : [
" x + 2 \\ n " ,
" x + 2 "
]
""" ,
"""
" source " : [
" Not script \\ n " ,
" Not script "
] ,
""" ,
"""
" source " : [
" x * 3 \\ n " ,
@ -981,7 +1171,6 @@ end end
@@ -981,7 +1171,6 @@ end end
" #| echo: false Quarto parameters "
] ,
""" ,
"""
" source " : [
" for i in 1:10 \\ n " ,
@ -990,7 +1179,6 @@ end end
@@ -990,7 +1179,6 @@ end end
" end "
]
""" ,
"""
" source " : [
" name: inputfile \\ n " ,
@ -999,7 +1187,6 @@ end end
@@ -999,7 +1187,6 @@ end end
" Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=v1.2.0/file.jl "
]
""" ,
"""
" source " : [
" # name: inputfile \\ n " ,
@ -1008,21 +1195,18 @@ end end
@@ -1008,21 +1195,18 @@ end end
" # Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=v1.2.0/file.jl "
]
""" ,
"""
" source " : [
" PLACEHOLDER1 \\ n " ,
" PLACEHOLDER2 "
]
""" ,
"""
" source " : [
" # PLACEHOLDER3 \\ n " ,
" # PLACEHOLDER4 "
]
""" ,
"""
" source " : [
" Some inline math: \$ \\ \\ frac{df}{dx} \$ , some multiline inline math: \$ y = \\ n " ,
@ -1032,13 +1216,11 @@ end end
@@ -1032,13 +1216,11 @@ end end
" \$ \$ "
]
""" ,
"""
" source " : [
" Indented markdown "
]
""" ,
"""
" source " : [
" for i in 1:10 \\ n " ,
@ -1047,27 +1229,25 @@ end end
@@ -1047,27 +1229,25 @@ end end
" end "
]
""" ,
"""
" metadata " : {
" meta " : " data "
}
""" ,
"""
" source " : [
" First multiline \\ n " ,
" comment "
]
""" ,
"""
" source " : [
" --- \\ n " ,
" \\ n " ,
" *This notebook was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).* "
]
""" ))
""" ,
) )
notebook = read ( joinpath ( outdir , " inputfile.ipynb " ) , String )
@ -1078,16 +1258,25 @@ end end
@@ -1078,16 +1258,25 @@ end end
lastidx = nextind ( notebook , last ( idx ) )
end
# test some of the required metadata
for metadata in ( " \" nbformat \" : " , " \" nbformat_minor \" : " , " \" metadata \" : { " , " \" language_info \" : { " ,
" \" file_extension \" : \" .jl \" " , " \" mimetype \" : \" application/julia \" " ,
" \" name \" : \" julia \" " , " \" version \" : " , " \" kernelspec \" : { " ,
" \" name \" : \" julia- " , " \" display_name \" : \" Julia " , " \" language \" : \" julia \" " )
for metadata in (
" \" nbformat \" : " ,
" \" nbformat_minor \" : " ,
" \" metadata \" : { " ,
" \" language_info \" : { " ,
" \" file_extension \" : \" .jl \" " ,
" \" mimetype \" : \" application/julia \" " ,
" \" name \" : \" julia \" " ,
" \" version \" : " ,
" \" kernelspec \" : { " ,
" \" name \" : \" julia- " ,
" \" display_name \" : \" Julia " ,
" \" language \" : \" julia \" " ,
)
@test occursin ( metadata , notebook )
end
# no tag -> latest directory
withenv ( TRAVIS_ENV ... ,
" TRAVIS_TAG " => " " ) do
withenv ( TRAVIS_ENV ... , " TRAVIS_TAG " => " " ) do
Literate . notebook ( inputfile , outdir , execute = false )
end
notebook = read ( joinpath ( outdir , " inputfile.ipynb " ) , String )
@ -1101,44 +1290,65 @@ end end
@@ -1101,44 +1290,65 @@ end end
@test occursin ( " fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/ " , notebook )
# GitHub Actions with PR preview build
withenv ( ACTIONS_ENV ... ,
withenv (
ACTIONS_ENV ... ,
" GITHUB_REF " => " refs/pull/42/merge " ,
" GITHUB_EVENT_NAME " => " pull_request " ) do
" GITHUB_EVENT_NAME " => " pull_request " ,
) do
Literate . notebook ( inputfile , outdir , execute = false )
end
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
withenv ( ACTIONS_ENV ... ,
" GITHUB_REF " => " refs/heads/master " ) do
withenv ( ACTIONS_ENV ... , " GITHUB_REF " => " refs/heads/master " ) do
Literate . notebook ( inputfile , outdir , execute = false )
end
notebook = read ( joinpath ( outdir , " inputfile.ipynb " ) , String )
@test occursin ( " fredrikekre/Literate.jl/blob/gh-pages/dev/ " , notebook )
# building under DocumentationGenerator.jl
withenv ( " DOCUMENTATIONGENERATOR " => " true " ,
" DOCUMENTATIONGENERATOR_BASE_URL " => " pkg.julialang.org/docs/Literate/XPnWG/1.2.0 " ) do
withenv (
" DOCUMENTATIONGENERATOR " => " true " ,
" DOCUMENTATIONGENERATOR_BASE_URL " => " pkg.julialang.org/docs/Literate/XPnWG/1.2.0 " ,
) do
Literate . notebook ( inputfile , outdir , execute = false )
end
notebook = read ( joinpath ( outdir , " inputfile.ipynb " ) , String )
@test occursin ( " jupyter.org/urls/pkg.julialang.org/docs/Literate/XPnWG/1.2.0/file.jl " , notebook )
@test_broken occursin ( " https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " , notebook )
@test occursin (
" jupyter.org/urls/pkg.julialang.org/docs/Literate/XPnWG/1.2.0/file.jl " ,
notebook ,
)
@test_broken occursin (
" https://github.com/fredrikekre/Literate.jl/blob/master/file.jl " ,
notebook ,
)
# pre- and post-processing
function post ( nb )
for cell in nb [ " cells " ]
for i in eachindex ( cell [ " source " ] )
cell [ " source " ] [ i ] = replace ( cell [ " source " ] [ i ] , " PLACEHOLDER2 " => " 2REDLOHECALP " )
cell [ " source " ] [ i ] = replace ( cell [ " source " ] [ i ] , " PLACEHOLDER4 " => " 4REDLOHECALP " )
cell [ " source " ] [ i ] =
replace ( cell [ " source " ] [ i ] , " PLACEHOLDER2 " => " 2REDLOHECALP " )
cell [ " source " ] [ i ] =
replace ( cell [ " source " ] [ i ] , " PLACEHOLDER4 " => " 4REDLOHECALP " )
end
end
return nb
end
Literate . notebook ( inputfile , outdir , execute = false ,
preprocess = x -> replace ( replace ( x , " PLACEHOLDER1 " => " 1REDLOHECALP " ) , " PLACEHOLDER3 " => " 3REDLOHECALP " ) ,
postprocess = post )
Literate . notebook (
inputfile ,
outdir ,
execute = false ,
preprocess = x -> replace (
replace ( x , " PLACEHOLDER1 " => " 1REDLOHECALP " ) ,
" PLACEHOLDER3 " => " 3REDLOHECALP " ,
) ,
postprocess = post ,
)
notebook = read ( joinpath ( outdir , " inputfile.ipynb " ) , String )
@test ! occursin ( " PLACEHOLDER1 " , notebook )
@test ! occursin ( " PLACEHOLDER2 " , notebook )
@ -1151,7 +1361,12 @@ end end
@@ -1151,7 +1361,12 @@ end end
# documenter = false (deprecated)
@test_deprecated r " The documenter=false keyword to Literate.notebook is deprecated. " begin
Literate . notebook ( inputfile , outdir , documenter = false , execute = false )
Literate . notebook (
inputfile ,
outdir ,
documenter = false ,
execute = false ,
)
end
notebook = read ( joinpath ( outdir , " inputfile.ipynb " ) , String )
@test ! occursin ( " # [Example](@id example-id " , notebook )
@ -1166,22 +1381,22 @@ end end
@@ -1166,22 +1381,22 @@ end end
# execute = true
Literate . notebook ( inputfile , outdir )
expected_outputs = rstrip . ( (
expected_outputs =
rstrip . ( (
"""
" cells " : [
""" ,
"""
" data " : {
" text/plain " : " 3 "
} ,
""" ,
"""
" text " : [
" 12345678910 "
]
""" ))
""" ,
) )
notebook = read ( joinpath ( outdir , " inputfile.ipynb " ) , String )
@ -1197,18 +1412,27 @@ end end
@@ -1197,18 +1412,27 @@ end end
write ( joinpath ( outdir , " issue31.jl " ) , " 10 + 21 " )
Literate . notebook ( inputfile , outdir )
notebook = read ( joinpath ( outdir , " inputfile.ipynb " ) , String )
@test occursin ( " \" data \" : { \n \" text/plain \" : \" 31 \" \n } " , notebook )
@test occursin (
" \" data \" : { \n \" text/plain \" : \" 31 \" \n } " ,
notebook ,
)
# test error when executing notebook
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
Literate . notebook ( inputfile , outdir )
catch err
err
end )
end
)
@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 )
# verify that inputfile exists
@ -1220,7 +1444,9 @@ end end
@@ -1220,7 +1444,9 @@ end end
@test isfile ( " inputfile.ipynb " )
# world time problem with `IJulia.display_dict`
write ( inputfile , """
write (
inputfile ,
"""
struct VegaLiteRenderable end
Base . show ( io :: IO , :: MIME " application/vnd.vegalite.v2+json " , :: VegaLiteRenderable ) =
write ( io , \ " \" \"
@ -1228,7 +1454,8 @@ end end
@@ -1228,7 +1454,8 @@ end end
\ " \" \" )
Base . Multimedia . istextmime ( :: MIME { Symbol ( " application/vnd.vegalite.v2+json " ) } ) = true
VegaLiteRenderable ( )
""" )
""" ,
)
Literate . notebook ( inputfile , outdir )
notebook = read ( joinpath ( outdir , " inputfile.ipynb " ) , String )
@test occursin ( " \" application/vnd.vegalite.v2+json \" : " , notebook )
@ -1269,7 +1496,7 @@ end end
@@ -1269,7 +1496,7 @@ end end
push! ( xs , x )
end
"""
for i in 1 : 9
for i = 1 : 9
script *= " \n #- \n xs[ $i ] "
end
write ( inputfile , script )
@ -1295,9 +1522,10 @@ end end
@@ -1295,9 +1522,10 @@ end end
# Cell 2 has 3 outputs: 2 display and one execute result
cellout = cells [ 2 ] [ " outputs " ]
@test length ( cellout ) == 3
for i in 1 : 3
for i = 1 : 3
exe_res = i == 3
@test cellout [ i ] [ " output_type " ] == ( exe_res ? " execute_result " : " display_data " )
@test cellout [ i ] [ " output_type " ] ==
( exe_res ? " execute_result " : " display_data " )
@test keys ( cellout [ i ] [ " data " ] ) == Set ( ( " text/plain " , " text/html " ) )
@test cellout [ i ] [ " data " ] [ " text/plain " ] == " DF( $i ) as text/plain "
@test cellout [ i ] [ " data " ] [ " text/html " ] == Any [ " DF( $i ) as text/html " ]
@ -1312,9 +1540,11 @@ end end
@@ -1312,9 +1540,11 @@ end end
@test ! haskey ( cellout [ 1 ] , " execution_count " )
end
end
end end
end
end
@testset " Configuration " begin ; Base . CoreLogging . with_logger ( Base . CoreLogging . NullLogger ( ) ) do
@testset " Configuration " begin
Base . CoreLogging . with_logger ( Base . CoreLogging . NullLogger ( ) ) do
mktempdir ( @__DIR__ ) do sandbox
cd ( sandbox ) do
# write content to inputfile
@ -1329,10 +1559,12 @@ end end
@@ -1329,10 +1559,12 @@ end end
)
# Overwriting of URLs
withenv ( " TRAVIS_REPO_SLUG " => " fredrikekre/Literate.jl " ,
withenv (
" TRAVIS_REPO_SLUG " => " fredrikekre/Literate.jl " ,
" TRAVIS_TAG " => " " ,
" TRAVIS_PULL_REQUEST " => " false " ,
" HAS_JOSH_K_SEAL_OF_APPROVAL " => " true " ) do
" HAS_JOSH_K_SEAL_OF_APPROVAL " => " true " ,
) do
Literate . script ( inputfile , outdir ; config = config )
end
script = read ( joinpath ( outdir , " inputfile.jl " ) , String )
@ -1341,19 +1573,35 @@ end end
@@ -1341,19 +1573,35 @@ end end
@test occursin ( " Link to binder: www.example3.com/file.jl " , script )
# 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 == pick_codefence ( Literate . FranklinFlavor ( ) , true , " testname " )
@test default_codefence == pick_codefence ( Literate . DocumenterFlavor ( ) , true , " testname " )
@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 " )
let expected_exception = ErrorException ( " QuartoFlavor does not support argument execute=true! " )
@test_throws expected_exception pick_codefence ( Literate . QuartoFlavor ( ) , true , " testname " )
@test documenter_codefence ==
pick_codefence ( Literate . DocumenterFlavor ( ) , false , " testname " )
let expected_exception = ErrorException (
" QuartoFlavor does not support argument execute=true! " ,
)
@test_throws expected_exception pick_codefence (
Literate . QuartoFlavor ( ) ,
true ,
" testname " ,
)
end
@test ( " ```{julia} " => " ``` " ) == pick_codefence ( Literate . QuartoFlavor ( ) , false , " testname " )
@test ( " ```{julia} " => " ``` " ) ==
pick_codefence ( Literate . QuartoFlavor ( ) , false , " testname " )
# 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 )
@test cfg [ " execute " ]
@test cfg [ " codefence " ] == ( " ````julia " => " ```` " )
@ -1362,4 +1610,5 @@ end end
@@ -1362,4 +1610,5 @@ end end
@test cfg [ " codefence " ] == ( " ````@example inputfile " => " ```` " )
end
end
end end
end
end