Browse Source

add keep_comments to Literate.script to keep markdown as comments in script output

pull/5/head
Fredrik Ekre 8 years ago
parent
commit
fab80c77bf
  1. 10
      src/Literate.jl
  2. 7
      test/runtests.jl

10
src/Literate.jl

@ -200,9 +200,12 @@ Keyword arguments:
- `documenter`: boolean that says if the source contains Documenter.jl specific things - `documenter`: boolean that says if the source contains Documenter.jl specific things
to filter out during script generation. Defaults to `true`. See the the manual to filter out during script generation. Defaults to `true`. See the the manual
section on [Interaction with Documenter](@ref Interaction-with-Documenter). section on [Interaction with Documenter](@ref Interaction-with-Documenter).
- `keep_comments`: boolean that, if set to `true`, keeps markdown lines (`#'`)
as comments in the output script. Defaults to `false`.
""" """
function script(inputfile, outputdir; preprocess = identity, postprocess = identity, function script(inputfile, outputdir; preprocess = identity, postprocess = identity,
name = filename(inputfile), documenter = true, kwargs...) name = filename(inputfile), documenter = true,
keep_comments::Bool=false, kwargs...)
# normalize paths # normalize paths
inputfile = realpath(abspath(inputfile)) inputfile = realpath(abspath(inputfile))
mkpath(outputdir) mkpath(outputdir)
@ -226,6 +229,11 @@ function script(inputfile, outputdir; preprocess = identity, postprocess = ident
write(ioscript, line, '\n') write(ioscript, line, '\n')
end end
write(ioscript, '\n') # add a newline between each chunk write(ioscript, '\n') # add a newline between each chunk
elseif isa(chunk, MDChunk) && keep_comments
for line in chunk.lines
write(ioscript, "#' ", line, '\n')
end
write(ioscript, '\n') # add a newline between each chunk
end end
end end

7
test/runtests.jl

@ -240,6 +240,13 @@ content = """
@test occursin("name: foobar", script) @test occursin("name: foobar", script)
@test !occursin("name: inputfile", script) @test !occursin("name: inputfile", script)
@test !occursin("name: @__NAME__", script) @test !occursin("name: @__NAME__", script)
# keep_comments
Literate.script(inputfile, outdir, keep_comments = true)
script = read(joinpath(outdir, "inputfile.jl"), String)
@test occursin("#' # Example", script)
@test occursin("#' foo, bar", script)
@test occursin("#' \\int f(x) dx", script)
end end
end end
end end

Loading…
Cancel
Save