Browse Source

Use a better placeholder example for preprocessing, fixes #89.

pull/96/head
Fredrik Ekre 6 years ago
parent
commit
4c1221f508
  1. 3
      docs/make.jl
  2. 14
      examples/example.jl

3
docs/make.jl

@ -13,8 +13,7 @@ EXAMPLE = joinpath(@__DIR__, "..", "examples", "example.jl")
OUTPUT = joinpath(@__DIR__, "src/generated") OUTPUT = joinpath(@__DIR__, "src/generated")
function preprocess(str) function preprocess(str)
str = replace(str, "MYVARIABLE" => "z") str = replace(str, "x = 123" => "y = 321"; count=1)
str = replace(str, "MYVALUE" => "1.0 + 2.0im")
return str return str
end end

14
examples/example.jl

@ -87,11 +87,17 @@ plot(x, [y1, y2])
# ### Custom processing # ### Custom processing
# #
# It is possible to give Literate custom pre- and post-processing functions. # It is possible to give Literate custom pre- and post-processing functions.
# For example, here we insert two placeholders, which we will replace with # For example, here we insert a placeholder value `x = 123` in the source, and use a
# something else at time of generation. We have here replaced our placeholders # preprocessing function that replaces it with `y = 321` in the rendered output.
# with `z` and `1.0 + 2.0im`:
MYVARIABLE = MYVALUE x = 123
# In this case the preprocessing function is defined by
function pre(s::String)
s = replace(s, "x = 123" => "y = 321")
return s
end
# ### [Documenter.jl interaction](@id documenter-interaction) # ### [Documenter.jl interaction](@id documenter-interaction)
# #

Loading…
Cancel
Save