@ -4,7 +4,7 @@ Since all packages are different, and may have different demands on how
@@ -4,7 +4,7 @@ Since all packages are different, and may have different demands on how
to create a nice example for the documentation it is important that
the package maintainer does not feel limited by the by default provided syntax
that this package offers. While you can generally come a long way by utilizing
[line filtering](@ref Filtering-Lines) there might be situations where you need
[line filtering](@ref Filtering-lines) there might be situations where you need
to manually hook into the generation and change things. In Literate this
is done by letting the user supply custom pre- and post-processing functions
It is often useful to filter out lines in the source depending on the output format.
For this purpose there are a number of "tokens" that can be used to mark the purpose of
@ -91,12 +92,6 @@ ending with `#hide` are filtered out similar to Documenter.jl.
@@ -91,12 +92,6 @@ ending with `#hide` are filtered out similar to Documenter.jl.
are filtered out *before* execution (if `execute=true`) and `#hide` lines
are filtered out *after* execution.
!!! compat "Literate 2.6"
The `#hide` token requires at least Literate version 2.6.
!!! compat "Literate 2.3"
Filter tokens at the *end of the line* requires at least Literate version 2.3.
!!! tip
The tokens can also be negated, for example a line starting with `#!nb` would
be included in markdown and script output, but filtered out for notebook output.
@ -127,7 +122,7 @@ using Test #src
@@ -127,7 +122,7 @@ using Test #src
The following convenience "macros"/source placeholders are always expanded:
@ -162,9 +157,3 @@ The following convenience "macros"/source placeholders are always expanded:
@@ -162,9 +157,3 @@ The following convenience "macros"/source placeholders are always expanded:
```
This variable is automatically determined on Travis CI, GitHub Actions and GitLab CI,
but can be configured, see [Configuration](@ref Configuration).
!!! compat "Literate 2.1"
GitHub Actions support for the macros above requires at least Literate version 2.1.
!!! compat "Literate 2.2"
GitLab CI support for the macros above requires at least Literate version 2.2.
Markdown output is generated by [`Literate.markdown`](@ref). The (default) markdown output
of the source snippet above is as follows:
Markdown output is generated by [`Literate.markdown`](@ref). There exist various "flavors"
of markdown and Literate supports some different flavors, see [Markdown flavors](@ref).
The default flavor is `Literate.DocumenterFlavor()` and, as the name suggest, it generates
markdown files meant to be used together with [Documenter.jl]
(https://juliadocs.github.io/Documenter.jl). The output of the source snippet above is as
follows:
```@eval
import Markdown
@ -29,7 +33,8 @@ an `@meta` block have been added, that sets the `EditURL` variable. This is used
@@ -29,7 +33,8 @@ an `@meta` block have been added, that sets the `EditURL` variable. This is used
by Documenter to redirect the "Edit on GitHub" link for the page,
see [Interaction with Documenter](@ref).
The `@example` blocks are wrapped in 4 consecutive backticks so as to allow for docstrings containing triple backticks, for example:
The `@example` blocks are wrapped in 4 consecutive backticks so as to allow for docstrings
containing triple backticks, for example:
````julia
"""
This function perform the following calculation:
@ -39,7 +44,8 @@ This function perform the following calculation:
@@ -39,7 +44,8 @@ This function perform the following calculation:
"""
f(x) = x[1] + x[2]
````
If your Julia code itself contains 4 consecutive backticks, you can use the keyword argument `codefence` to setup 5 backticks for code blocks, see [Configuration](@ref).
If your Julia code itself contains 4 consecutive backticks, you can use the keyword
argument `codefence` to setup 5 backticks for code blocks, see [Configuration](@ref).
It possible to configure `Literate.markdown` to also evaluate code snippets, capture the
result and include it in the output, by passing `execute=true` as a keyword argument.
@ -54,17 +60,14 @@ x = 1//3
@@ -54,17 +60,14 @@ x = 1//3
`````
In this example the output is just plain text. However, if the resulting value of the code
block can be displayed as an image (png or jpeg) Literate will include the image
representation of the output.
block can be displayed as an image (image/png or image/jpeg), HTML (text/html) or markdown
(text/markdown) Literate will include the richest representation of the output.
!!! note
Since Documenter executes and captures results of `@example` block it is not necessary
to use `execute=true` for markdown output that is meant to be used as input to
Documenter.
!!! compat "Literate 2.4"
Code execution of markdown output requires at least Literate version 2.4.
See the section about [Configuration](@ref) for more information about how to configure the
behavior and resulting output of [`Literate.markdown`](@ref).
Notebook output is generated by [`Literate.notebook`](@ref). The (default) notebook output
of the source snippet can be seen here: [notebook.ipynb](generated/notebook.ipynb).
@ -136,7 +135,7 @@ y = 2//5
@@ -136,7 +135,7 @@ y = 2//5
# For more information about RISE, see [the docs](https://rise.readthedocs.io/en/stable/usage.html)
```
## [**4.3.** Script Output](@id Script-Output)
## [**4.3.** Script output](@id Script-output)
Script output is generated by [`Literate.script`](@ref). The (default) script output of the
source snippet above is as follows:
@ -166,9 +165,6 @@ The behavior of [`Literate.markdown`](@ref), [`Literate.notebook`](@ref) and
@@ -166,9 +165,6 @@ The behavior of [`Literate.markdown`](@ref), [`Literate.notebook`](@ref) and
ways to do this; pass `config::Dict` as a keyword argument, or pass individual
keyword arguments.
!!! compat "Literate 2.2"
Passing configuration as a dictionary requires at least Literate version 2.2.
!!! note "Configuration precedence"
Individual keyword arguments take precedence over the `config` dictionary, so for e.g.
`Literate.markdown(...; config = Dict("name" => "hello"), name = "world")` the
@ -20,7 +20,7 @@ internal processing. Next, line filtering is performed, see [Filtering Lines](@r
@@ -20,7 +20,7 @@ internal processing. Next, line filtering is performed, see [Filtering Lines](@r
meaning that lines starting with `#md `, `#nb ` or `#jl ` are handled (either just
the token itself is removed, or the full line, depending on the output target).
The last pre-processing step is to expand the convenience "macros" described