-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathliterate.jl
56 lines (53 loc) · 1.66 KB
/
literate.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Retrieve filename of literate script
if length(ARGS) != 2
error("please specify the literate script and the output directory")
end
const SCRIPTJL = ARGS[1]
const OUTDIR = ARGS[2]
# Activate environment
using Pkg: Pkg
Pkg.activate(dirname(SCRIPTJL))
# Note that each example's Project.toml must include Literate as a dependency
Pkg.instantiate()
using Literate: Literate
# Add link to nbviewer below the first heading of level 1
function preprocess(content)
sub = SubstitutionString(
"""
#md # ```@meta
#md # EditURL = "@__REPO_ROOT_URL__/examples/@__NAME__/script.jl"
#md # ```
#md #
\\0
#
#md # [](@__NBVIEWER_ROOT_URL__/examples/@__NAME__.ipynb)
#md #
# *You are seeing the
#md # HTML output generated by [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl) and
#nb # notebook output generated by
# [Literate.jl](https://github.com/fredrikekre/Literate.jl) from the
# [Julia source file](@__REPO_ROOT_URL__/examples/@__NAME__/script.jl).
#md # The corresponding notebook can be viewed in [nbviewer](@__NBVIEWER_ROOT_URL__/examples/@__NAME__.ipynb).*
#nb # The rendered HTML can be viewed [in the docs](https://juliagaussianprocesses.github.io/KernelFunctions.jl/dev/examples/@__NAME__/).*
#
""",
)
return replace(content, r"^# # [^\n]*"m => sub; count=1)
end
# Convert to markdown and notebook
Literate.markdown(
SCRIPTJL,
OUTDIR;
name=basename(dirname(SCRIPTJL)),
documenter=false,
execute=true,
preprocess=preprocess,
)
Literate.notebook(
SCRIPTJL,
OUTDIR;
name=basename(dirname(SCRIPTJL)),
documenter=false,
execute=true,
preprocess=preprocess,
)