Browse Source

allow `:color` in context

pull/275/head
t-bltg 5 months ago
parent
commit
34df6dd9bc
  1. 10
      src/Literate.jl

10
src/Literate.jl

@ -617,14 +617,14 @@ function markdown(inputfile, outputdir = pwd(); config::AbstractDict = Dict(), k
# create the markdown file # create the markdown file
sb = sandbox() sb = sandbox()
iomd = IOBuffer() iomd = IOContext(PipeBuffer(), :color => get(kwargs, :color, Base.get_have_color()))
for (chunknum, chunk) in enumerate(chunks) for (chunknum, chunk) in enumerate(chunks)
if isa(chunk, MDChunk) if isa(chunk, MDChunk)
for line in chunk.lines for line in chunk.lines
write(iomd, line.second, '\n') # skip indent here write(iomd, line.second, '\n') # skip indent here
end end
else # isa(chunk, CodeChunk) else # isa(chunk, CodeChunk)
iocode = IOBuffer() iocode = PipeBuffer()
codefence = config["codefence"]::Pair codefence = config["codefence"]::Pair
write(iocode, codefence.first) write(iocode, codefence.first)
# make sure the code block is finalized if we are printing to ```@example # make sure the code block is finalized if we are printing to ```@example
@ -644,7 +644,7 @@ function markdown(inputfile, outputdir = pwd(); config::AbstractDict = Dict(), k
write(iocode, "nothing #hide\n") write(iocode, "nothing #hide\n")
end end
write(iocode, codefence.second, '\n') write(iocode, codefence.second, '\n')
any(write_line, chunk.lines) && write(iomd, seekstart(iocode)) any(write_line, chunk.lines) && write(iomd, read(iocode, String))
if execute if execute
cd(config["literate_outputdir"]) do cd(config["literate_outputdir"]) do
execute_markdown!( execute_markdown!(
@ -665,7 +665,7 @@ function markdown(inputfile, outputdir = pwd(); config::AbstractDict = Dict(), k
end end
# custom post-processing from user # custom post-processing from user
content = config["postprocess"](String(take!(iomd))) content = config["postprocess"](read(iomd, String))
# write to file # write to file
outputfile = write_result(content, config) outputfile = write_result(content, config)
@ -713,7 +713,7 @@ function execute_markdown!(
end end
# fallback to text/plain # fallback to text/plain
write(io, plain_fence.first) write(io, plain_fence.first)
Base.invokelatest(show, io, "text/plain", r) Base.invokelatest(show, io, MIME("text/plain"), r)
write(io, plain_fence.second, '\n') write(io, plain_fence.second, '\n')
return return
elseif !isempty(str) elseif !isempty(str)

Loading…
Cancel
Save