From 7fc99585f72fc2d54a958aef40e85b3e044e1b49 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Wed, 8 Nov 2023 00:07:35 +0100 Subject: [PATCH] `Literate.markdown`: fix output directory for images This patch fixes a bug where `Literate.markdown` with `execute=true` would (try to) output images in the wrong directory. This only occured when passing a relative output directory. Fixes #228. --- CHANGELOG.md | 8 +++++++- src/Literate.jl | 3 ++- test/runtests.jl | 18 ++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1169d15..704b64c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - +## [Unreleased] +### Fixed +- Fix a bug where `Literate.markdown` with `execute=true` would (try to) output images in + the wrong directory. This only occured when passing a relative output directory. + ([#228][github-228], [#229][github-229]) ## [2.15.0] - 2023-09-05 ### Added @@ -260,6 +264,8 @@ https://discourse.julialang.org/t/ann-literate-jl/10651 for release announcement [github-221]: https://github.com/fredrikekre/Literate.jl/pull/221 [github-222]: https://github.com/fredrikekre/Literate.jl/issues/222 [github-223]: https://github.com/fredrikekre/Literate.jl/pull/223 +[github-228]: https://github.com/fredrikekre/Literate.jl/issues/228 +[github-229]: https://github.com/fredrikekre/Literate.jl/pull/229 [Unreleased]: https://github.com/fredrikekre/Literate.jl/compare/v2.15.0...HEAD [2.15.0]: https://github.com/fredrikekre/Literate.jl/compare/v2.14.2...v2.15.0 diff --git a/src/Literate.jl b/src/Literate.jl index f7c964d..f12440c 100644 --- a/src/Literate.jl +++ b/src/Literate.jl @@ -573,7 +573,8 @@ function markdown(inputfile, outputdir=pwd(); config::AbstractDict=Dict(), kwarg any(write_line, chunk.lines) && write(iomd, seekstart(iocode)) if execute cd(config["literate_outputdir"]) do - execute_markdown!(iomd, sb, join(chunk.lines, '\n'), outputdir; + execute_markdown!(iomd, sb, join(chunk.lines, '\n'), + config["literate_outputdir"]; inputfile=config["literate_inputfile"], fake_source=config["literate_outputfile"], flavor=config["flavor"], diff --git a/test/runtests.jl b/test/runtests.jl index 2e5894a..d56f304 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -891,8 +891,22 @@ end end write(f, "1 + 1") Literate.markdown(f, outdir) @test occursin("file_with_space", read(joinpath(outdir, "file with space.md"), String)) - end - end + + # Relative output directory + image output + # https://github.com/fredrikekre/Literate.jl/issues/228 + write( + inputfile, + """ + struct SVG end + Base.show(io::IO, mime::MIME"image/svg+xml", ::SVG) = print(io, "issue228") + SVG() + """, + ) + Literate.markdown(inputfile, relpath(outdir); execute=true, + flavor=Literate.CommonMarkFlavor()) + @test read(joinpath(outdir, "inputfile-1.svg"), String) == "issue228" + end # cd(sandbox) + end # mktemp end end @testset "Literate.notebook" begin; Base.CoreLogging.with_logger(Base.CoreLogging.NullLogger()) do