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

14
examples/example.jl

@ -87,11 +87,17 @@ plot(x, [y1, y2]) @@ -87,11 +87,17 @@ plot(x, [y1, y2])
# ### Custom processing
#
# It is possible to give Literate custom pre- and post-processing functions.
# For example, here we insert two placeholders, which we will replace with
# something else at time of generation. We have here replaced our placeholders
# with `z` and `1.0 + 2.0im`:
# For example, here we insert a placeholder value `x = 123` in the source, and use a
# preprocessing function that replaces it with `y = 321` in the rendered output.
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)
#

Loading…
Cancel
Save