Browse Source

`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.
pull/229/head
Fredrik Ekre 2 years ago
parent
commit
3aa4226dd2
  1. 8
      CHANGELOG.md
  2. 3
      src/Literate.jl
  3. 18
      test/runtests.jl

8
CHANGELOG.md

@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file. @@ -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] -->
## [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 @@ -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

3
src/Literate.jl

@ -573,7 +573,8 @@ function markdown(inputfile, outputdir=pwd(); config::AbstractDict=Dict(), kwarg @@ -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"],

18
test/runtests.jl

@ -891,8 +891,22 @@ end end @@ -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

Loading…
Cancel
Save