Browse Source

Handle svg+xml by default.

pull/183/head
Tamás K. Papp 4 years ago
parent
commit
83b4512e67
  1. 3
      src/Literate.jl
  2. 15
      test/runtests.jl

3
src/Literate.jl

@ -260,7 +260,8 @@ function create_configuration(inputfile; user_config, user_kwargs, type=nothing)
!get(user_config, "execute", cfg["execute"]) ? !get(user_config, "execute", cfg["execute"]) ?
("````@example $(get(user_config, "name", replace(cfg["name"], r"\s" => "_")))" => "````") : ("````@example $(get(user_config, "name", replace(cfg["name"], r"\s" => "_")))" => "````") :
("````julia" => "````") ("````julia" => "````")
cfg["mime_extensions"] = [(MIME("image/png"), ".png"), (MIME("image/jpeg"), ".jpeg")] cfg["mime_extensions"] = [(MIME("image/png"), ".png"), (MIME("image/jpeg"), ".jpeg"),
(MIME("image/svg+xml"), ".svg")]
# Guess the package (or repository) root url # Guess the package (or repository) root url
edit_commit = "master" # TODO: Make this configurable like Documenter? edit_commit = "master" # TODO: Make this configurable like Documenter?
deploy_branch = "gh-pages" # TODO: Make this configurable like Documenter? deploy_branch = "gh-pages" # TODO: Make this configurable like Documenter?

15
test/runtests.jl

@ -778,6 +778,10 @@ end end
Base.show(io::IO, mime::MIME"image/jpeg", ::JPEG) = print(io, "JPEG") Base.show(io::IO, mime::MIME"image/jpeg", ::JPEG) = print(io, "JPEG")
JPEG() JPEG()
#- #-
struct SVG end
Base.show(io::IO, mime::MIME"image/svg+xml", ::SVG) = print(io, "SVG")
SVG()
#-
struct MD end struct MD end
Base.show(io::IO, mime::MIME"text/markdown", ::MD) = print(io, "# " * "MD") Base.show(io::IO, mime::MIME"text/markdown", ::MD) = print(io, "# " * "MD")
Base.show(io::IO, mime::MIME"text/html", ::MD) = Base.show(io::IO, mime::MIME"text/html", ::MD) =
@ -805,6 +809,7 @@ end end
@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
@test occursin(r"!\[\]\(\d+\.png\)", markdown) # image/png @test occursin(r"!\[\]\(\d+\.png\)", markdown) # image/png
@test occursin(r"!\[\]\(\d+\.jpeg\)", markdown) # image/jpeg @test occursin(r"!\[\]\(\d+\.jpeg\)", markdown) # image/jpeg
e @test occursin(r"!\[\]\(\d+\.svg\)", markdown) # image/svg+xml, fredrikekre/Literate.jl#182
@test occursin("# MD", markdown) # text/markdown @test occursin("# MD", markdown) # text/markdown
@test occursin("```@raw html\n<h1>MD</h1>\n```", markdown) # text/html @test occursin("```@raw html\n<h1>MD</h1>\n```", markdown) # text/html
@test occursin("```\nhello, world\n```", markdown) # stdout/stderr @test occursin("```\nhello, world\n```", markdown) # stdout/stderr
@ -841,16 +846,6 @@ end end
Literate.markdown(f, outdir) 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))
# fredrikekre/Literate.jl#182
write(inputfile, """
struct SVG end
Base.show(io::IO, mime::MIME"image/svg+xml", ::SVG) = print(io, "SVG")
SVG()
""")
Literate.markdown(inputfile, outdir; execute=true,
config = Dict("mime_extensions" => [(MIME("image/svg+xml"), ".svg")]))
markdown = read(joinpath(outdir, "inputfile.md"), String)
@test occursin(r"!\[\]\(\d+\.svg\)", markdown) # image/svg
end end
end end
end end end end

Loading…
Cancel
Save