Skip to content

Commit

Permalink
Literate.markdown: fix output directory for images
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fredrikekre committed Nov 7, 2023
1 parent 5047103 commit 3aa4226
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/Literate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
18 changes: 16 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3aa4226

Please sign in to comment.