diff --git a/src/Literate.jl b/src/Literate.jl index 10085db..5428c85 100644 --- a/src/Literate.jl +++ b/src/Literate.jl @@ -200,9 +200,12 @@ Keyword arguments: - `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 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, - name = filename(inputfile), documenter = true, kwargs...) + name = filename(inputfile), documenter = true, + keep_comments::Bool=false, kwargs...) # normalize paths inputfile = realpath(abspath(inputfile)) mkpath(outputdir) @@ -226,6 +229,11 @@ function script(inputfile, outputdir; preprocess = identity, postprocess = ident write(ioscript, line, '\n') end 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 diff --git a/test/runtests.jl b/test/runtests.jl index 7df1647..3de94f8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -240,6 +240,13 @@ content = """ @test occursin("name: foobar", script) @test !occursin("name: inputfile", 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