import Literate, JSON import Literate: Chunk, MDChunk, CodeChunk using Test # compare content of two parsed chunk vectors function compare_chunks(chunks1, chunks2) @test length(chunks1) == length(chunks2) for (c1, c2) in zip(chunks1, chunks2) # compare types @test typeof(c1) == typeof(c2) # test that the chunk don't start or end with empty line @test first(c1.lines) != "" && first(c1.lines) != ("" => "") @test first(c2.lines) != "" && first(c2.lines) != ("" => "") @test last(c1.lines) != "" && last(c1.lines) != ("" => "") @test last(c2.lines) != "" && last(c2.lines) != ("" => "") # compare content for (l1, l2) in zip(c1.lines, c2.lines) @test l1 == l2 end # test continued code if isa(c1, CodeChunk) @test c1.continued == c2.continued end end end @testset "Literate.parse" begin content = """ # Line 1 Line 2 # Line 3 # # Line 5 Line 6 Line 8 # Line 9 #- # Line 11 Line 12 #- Line 14 # Line 15 #----------------- # Line 17 Line 18 #----------------- Line 20 # Line 21 Line 22 Line 23 Line 24 #- Line 26 Line 27 #+ Line 29 #- Line 31 Line 32 # Line 33 #+ Line 34 #- Line 36 #+ Line 38 #+ Line 40 #- Line 42 Line 43 # Line 44 #+ Line 45 # Line 46 #+ Line 47 # Line 48 #Line 49 Line 50 # # # Line 53 # # #- ## Line 57 Line 58 ## Line 59 ##Line 60 #- # Line 62 # # Line 63 Line 64 ## Line 65 Line 66 Line 67 #- # #- # #- ## Line 73 ## ## Line 75 #- ## Line 77 ## ## Line 79 """ expected_chunks = Chunk[ MDChunk(["" => "Line 1"]), CodeChunk(["Line 2"], false), MDChunk(["" => "Line 3", "" => "","" => "Line 5"]), CodeChunk(["Line 6", "","Line 8"], false), MDChunk(["" => "Line 9"]), MDChunk(["" => "Line 11"]), CodeChunk(["Line 12"], false), CodeChunk(["Line 14"], false), MDChunk(["" => "Line 15"]), MDChunk(["" => "Line 17"]), CodeChunk(["Line 18"], false), CodeChunk(["Line 20"], false), MDChunk(["" => "Line 21"]), CodeChunk(["Line 22", " Line 23", "Line 24"], false), CodeChunk(["Line 26", " Line 27"], true), CodeChunk(["Line 29"], false), CodeChunk(["Line 31", " Line 32"], true), MDChunk(["" => "Line 33"]), CodeChunk(["Line 34"], false), CodeChunk(["Line 36"], true), CodeChunk([" Line 38"], true), CodeChunk(["Line 40"], false), CodeChunk(["Line 42", " Line 43"], true), MDChunk(["" => "Line 44"]), CodeChunk([" Line 45"], true), MDChunk(["" => "Line 46"]), CodeChunk(["Line 47"], false), MDChunk(["" => "Line 48"]), CodeChunk(["#Line 49", "Line 50"], false), MDChunk(["" => "Line 53"]), CodeChunk(["# Line 57", "Line 58", "# Line 59", "##Line 60"], false), MDChunk([" " => "Line 62", " " => "# Line 63"]), CodeChunk(["Line 64", " # Line 65", " Line 66", "Line 67"], false), CodeChunk(["# Line 73", "#", "# Line 75"], false), CodeChunk([" # Line 77", " #", " # Line 79"], false), ] parsed_chunks = Literate.parse(content) compare_chunks(parsed_chunks, expected_chunks) # test leading/trailing whitespace removal io = IOBuffer() iows = IOBuffer() for c in expected_chunks if isa(c, CodeChunk) foreach(x-> println(io, x), c.lines) foreach(x-> println(iows, x, " "), c.lines) else foreach(x -> println(io, "# ", x), c.lines) foreach(x -> println(iows, "# ", x, " "), c.lines) end println(io, "#-") println(iows, "#-") foreach(x -> println(iows), 1:rand(2:5)) end compare_chunks(Literate.parse(String(take!(io))), Literate.parse(String(take!(iows)))) end # testset parser content = """ # # [Example](@id example-id) # [foo](@ref), [bar](@ref bbaarr) x = 1 #md # Only markdown # Only markdown #md #md x + 1 x + 1 #md #!md # Not markdown # Not markdown #!md #!md x * 1 x * 1 #!md #nb # Only notebook # Only notebook #nb #nb x + 2 x + 2 #nb #!nb # Not notebook # Not notebook #!nb #!nb x * 2 x * 2 #!nb #jl # Only script # Only script #jl #jl x + 3 x + 3 #jl #!jl # Not script # Not script #!jl #!jl x * 3 x * 3 #!jl #src # Source code only Source code only #src ## # Comment ## another comment #- for i in 1:10 print(i) # some markdown in a code block #+ end # name: @__NAME__ # Link to repo root: @__REPO_ROOT_URL__/file.jl # Link to nbviewer: @__NBVIEWER_ROOT_URL__/file.jl # Link to binder: @__BINDER_ROOT_URL__/file.jl ## name: @__NAME__ ## Link to repo root: @__REPO_ROOT_URL__/file.jl ## Link to nbviewer: @__NBVIEWER_ROOT_URL__/file.jl ## Link to binder: @__BINDER_ROOT_URL__/file.jl # PLACEHOLDER1 # PLACEHOLDER2 ## PLACEHOLDER3 ## PLACEHOLDER4 # Some math: # ```math # \\int f(x) dx # ``` #- # Indented markdown for i in 1:10 # Indented markdown #+ ## Indented comment end # 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 #= First multiline comment =# #======================= Second multiline comment =======================# """ const TRAVIS_ENV = Dict( "TRAVIS_REPO_SLUG" => "fredrikekre/Literate.jl", "TRAVIS_TAG" => "v1.2.0", "TRAVIS_PULL_REQUEST" => "false", "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true", "TRAVIS_BUILD_DIR" => normpath(joinpath(@__DIR__, "..")), ) const ACTIONS_ENV = Dict( "GITHUB_ACTIONS" => "true", "GITHUB_ACTION" => "Build docs", "GITHUB_REPOSITORY" => "fredrikekre/Literate.jl", "GITHUB_EVENT_NAME" => "push", "GITHUB_REF" => "refs/tags/v1.2.0", "GITHUB_WORKSPACE" => normpath(joinpath(@__DIR__, "..")), (k => nothing for k in keys(TRAVIS_ENV))..., ) const GITLAB_ENV = Dict( "GITLAB_CI" => "true", "CI_PROJECT_URL" => "https://gitlab.com/fredrikekre/Literate.jl", "CI_PAGES_URL" => "https://fredrikekre.gitlab.io/Literate.jl", "CI_PROJECT_DIR" => normpath(joinpath(@__DIR__, "..")), (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 mktempdir(@__DIR__) do sandbox cd(sandbox) do # write content to inputfile inputfile = "inputfile.jl" write(inputfile, content) outdir = mktempdir(pwd()) # test defaults withenv(TRAVIS_ENV...) do Literate.script(inputfile, outdir) end expected_script = """ x = 1 x * 1 x * 1 x * 2 x * 2 x + 3 x + 3 # # Comment # another comment for i in 1:10 print(i) end # name: inputfile # Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl # Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/file.jl # Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=v1.2.0/file.jl # PLACEHOLDER3 # PLACEHOLDER4 for i in 1:10 # Indented comment end 1 + 1; hidden = 12 #hide hidden * hidden #hide hidden2 = 12 #hide hidden2 * hidden2 # This file was generated using Literate.jl, https://github.com/fredrikekre/Literate.jl """ script = read(joinpath(outdir, "inputfile.jl"), String) @test script == expected_script # Travis with with PR preview build 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) # Travis with no tag -> dev directory 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) # 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) # GitHub Actions with PR preview build withenv(ACTIONS_ENV..., "GITHUB_EVENT_NAME" => "pull_request", "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) # GitHub Actions without a tag -> dev directory 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) # building under DocumentationGenerator.jl 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) # pre- and post-processing Literate.script(inputfile, outdir, preprocess = x -> replace(x, "PLACEHOLDER3" => "3REDLOHECALP"), postprocess = x -> replace(x, "PLACEHOLDER4" => "4REDLOHECALP")) script = read(joinpath(outdir, "inputfile.jl"), String) @test !occursin("PLACEHOLDER1", script) @test !occursin("PLACEHOLDER2", script) @test !occursin("PLACEHOLDER3", script) @test !occursin("PLACEHOLDER4", script) @test occursin("3REDLOHECALP", script) @test occursin("4REDLOHECALP", script) # name Literate.script(inputfile, outdir, name = "foobar") script = read(joinpath(outdir, "foobar.jl"), String) @test occursin("name: foobar", script) @test !occursin("name: inputfile", script) @test !occursin("name: @__NAME__", script) # keep_comments Literate.script(inputfile, outdir, keep_comments = true) script = read(joinpath(outdir, "inputfile.jl"), String) @test occursin("# # Example", script) @test occursin("# foo, bar", script) @test occursin("# \\int f(x) dx", script) @test occursin("# First multiline", script) @test occursin("# Second multiline comment", script) # mdstrings mdstrings_file = "inputfile_mdstrings.jl" write(mdstrings_file, """ md\"\"\" # Markdown header Content of the multiline markdown string \"\"\" #- #=== # Markdown header 2 Content of the multiline comment ===# 2 + 2 """) Literate.script(mdstrings_file, outdir, keep_comments = true, credit=false) script = read(joinpath(outdir, mdstrings_file), String) @test strip(script) == """ md\"\"\" # Markdown header Content of the multiline markdown string \"\"\" # # Markdown header 2 # # Content of the multiline # comment 2 + 2""" Literate.script(mdstrings_file, outdir, keep_comments = true, mdstrings = true, credit=false) script = read(joinpath(outdir, mdstrings_file), String) @test strip(script) == """ # # Markdown header # # Content of the multiline markdown # string # # Markdown header 2 # # Content of the multiline # comment 2 + 2""" # verify that inputfile exists @test_throws ArgumentError Literate.script("nonexistent.jl", outdir) # default output directory Literate.script(inputfile; name="default-output-directory") @test isfile("default-output-directory.jl") @test_throws ArgumentError Literate.script(inputfile) end end end end @testset "Literate.markdown" begin; Base.CoreLogging.with_logger(Base.CoreLogging.NullLogger()) do mktempdir(@__DIR__) do sandbox cd(sandbox) do # write content to inputfile inputfile = "inputfile.jl" write(inputfile, content) outdir = mktempdir(pwd()) # test defaults withenv(TRAVIS_ENV...) do Literate.markdown(inputfile, outdir) end expected_markdown = """ ```@meta EditURL = "https://github.com/fredrikekre/Literate.jl/blob/master/test/$(basename(sandbox))/inputfile.jl" ``` # [Example](@id example-id) [foo](@ref), [bar](@ref bbaarr) ````@example inputfile x = 1 ```` Only markdown Only markdown ````@example inputfile x + 1 x + 1 ```` Not notebook Not notebook ````@example inputfile x * 2 x * 2 ```` Not script Not script ````@example inputfile x * 3 x * 3 # # Comment # another comment ```` ````@example inputfile; continued = true for i in 1:10 print(i) ```` some markdown in a code block ````@example inputfile end ```` name: inputfile Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/file.jl Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=v1.2.0/file.jl ````@example inputfile # name: inputfile # Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl # Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/file.jl # Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=v1.2.0/file.jl ```` PLACEHOLDER1 PLACEHOLDER2 ````@example inputfile # PLACEHOLDER3 # PLACEHOLDER4 ```` Some math: ```math \\int f(x) dx ``` Indented markdown ````@example inputfile; continued = true for i in 1:10 ```` Indented markdown ````@example inputfile # Indented comment end ```` Semicolon output supression ````@example inputfile 1 + 1; nothing #hide ```` Completely hidden ````@example inputfile hidden = 12 #hide hidden * hidden #hide ```` Partially hidden ````@example inputfile hidden2 = 12 #hide hidden2 * hidden2 ```` First multiline comment Second multiline comment --- *This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).* """ markdown = read(joinpath(outdir, "inputfile.md"), String) @test markdown == expected_markdown # Travis with PR preview build 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) # Travis with no tag -> dev directory 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) # 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) # GitHub Actions with PR preview build withenv(ACTIONS_ENV..., "GITHUB_REF" => "refs/pull/42/merge", "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) # GitHub Actions without a tag -> dev directory 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) # 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) # building under DocumentationGenerator.jl 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) # 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")) markdown = read(joinpath(outdir, "inputfile.md"), String) @test !occursin("PLACEHOLDER1", markdown) @test !occursin("PLACEHOLDER2", markdown) @test !occursin("PLACEHOLDER3", markdown) @test !occursin("PLACEHOLDER4", markdown) @test occursin("1REDLOHECALP", markdown) @test occursin("2REDLOHECALP", markdown) @test occursin("3REDLOHECALP", markdown) @test occursin("4REDLOHECALP", markdown) # flavor = CommonMarkFlavor() Literate.markdown(inputfile, outdir, flavor = Literate.CommonMarkFlavor()) markdown = read(joinpath(outdir, "inputfile.md"), String) @test occursin("```julia", markdown) @test !occursin(r"`{3,}@example", markdown) @test !occursin("continued = true", markdown) @test !occursin("EditURL", markdown) @test !occursin("#hide", markdown) # documenter = false (deprecated) @test_deprecated r"The documenter=true keyword to Literate.markdown is deprecated" begin Literate.markdown(inputfile, outdir, documenter = true) end @test_deprecated r"The documenter=false keyword to Literate.markdown is deprecated" begin Literate.markdown(inputfile, outdir, documenter = false) end markdown = read(joinpath(outdir, "inputfile.md"), String) @test occursin("```julia", markdown) @test !occursin(r"`{3,}@example", markdown) # codefence Literate.markdown(inputfile, outdir, codefence = "```c" => "```") markdown = read(joinpath(outdir, "inputfile.md"), String) @test occursin("```c", markdown) @test !occursin(r"`{3,}@example", markdown) @test !occursin("```julia", markdown) # name Literate.markdown(inputfile, outdir, name = "foobar") markdown = read(joinpath(outdir, "foobar.md"), String) @test occursin(r"`{3,}@example foobar", markdown) @test !occursin(r"`{3,}@example inputfile", markdown) @test occursin("name: foobar", markdown) @test !occursin("name: inputfile", markdown) @test !occursin("name: @__NAME__", markdown) # mdstrings Literate.markdown(inputfile, outdir, mdstrings = true) markdown = read(joinpath(outdir, "inputfile.md"), String) @test !occursin("md\"\"\"", markdown) # execute write(inputfile, """ using DisplayAs #- 1+1 #- [1 2; 3 4] #- struct PNG end Base.show(io::IO, mime::MIME"image/png", ::PNG) = print(io, "PNG") PNG() #- struct JPEG end Base.show(io::IO, mime::MIME"image/jpeg", ::JPEG) = print(io, "JPEG") JPEG() #- struct MD end Base.show(io::IO, mime::MIME"text/markdown", ::MD) = print(io, "# " * "MD") Base.show(io::IO, mime::MIME"text/html", ::MD) = print(io, "