Browse Source

use a better example, show real notebook (#5)

pull/4/head
Fredrik Ekre 8 years ago committed by GitHub
parent
commit
0105ffe273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      docs/make.jl
  2. 12
      docs/src/outputformats.jl
  3. 76
      docs/src/outputformats.md

17
docs/make.jl

@ -15,6 +15,23 @@ Literate.markdown(EXAMPLE, OUTPUT, preprocess = preprocess)
Literate.notebook(EXAMPLE, OUTPUT, preprocess = preprocess) Literate.notebook(EXAMPLE, OUTPUT, preprocess = preprocess)
Literate.script(EXAMPLE, OUTPUT, preprocess = preprocess) Literate.script(EXAMPLE, OUTPUT, preprocess = preprocess)
# generate the example notebook for the documentation, keep in sync with outputformats.md
Literate.markdown(joinpath(@__DIR__, "src/outputformats.jl"), OUTPUT; credit = false, name = "name")
Literate.notebook(joinpath(@__DIR__, "src/outputformats.jl"), OUTPUT, name = "notebook")
Literate.script(joinpath(@__DIR__, "src/outputformats.jl"), OUTPUT, credit = false)
# replace the link in outputformats.md
travis_tag = get(ENV, "TRAVIS_TAG", "")
folder = isempty(travis_tag) ? "latest" : travis_tag
url = "https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/$(folder)/"
if get(ENV, "HAS_JOSH_K_SEAL_OF_APPROVAL", "") == "true"
str = read(joinpath(@__DIR__, "src/outputformats.md"), String)
@show url
str = replace(str, "[notebook.ipynb](generated/notebook.ipynb)." => "[notebook.ipynb]($(url)generated/notebook.ipynb).")
write(joinpath(@__DIR__, "src/outputformats.md"), str)
end
makedocs( makedocs(
modules = [Literate], modules = [Literate],
format = :html, format = :html,

12
docs/src/outputformats.jl

@ -0,0 +1,12 @@
#' # Rational numbers
#'
#' In julia rational numbers can be constructed with the `//` operator.
#' Lets define two rational numbers, `x` and `y`:
x = 1//3
#-
y = 2//5
#' When adding `x` and `y` together we obtain a new rational number:
z = x + y

76
docs/src/outputformats.md

@ -3,19 +3,8 @@
When the source is parsed, and have been processed it is time to render the output. When the source is parsed, and have been processed it is time to render the output.
We will consider the following source snippet: We will consider the following source snippet:
```julia ```@eval
#' # Rational numbers Markdown.parse("```julia\n" * rstrip(read("outputformats.jl", String)) * "\n```")
#'
#' In julia rational numbers can be constructed with the `//` operator.
#' Lets define two rational numbers, `x` and `y`:
x = 1//3
#-
y = 2//5
#' When adding `x` and `y` together we obtain a new rational number:
z = x + y
``` ```
and see how this is rendered in each of the output formats. and see how this is rendered in each of the output formats.
@ -24,29 +13,18 @@ and see how this is rendered in each of the output formats.
The (default) markdown output of the source snippet above is as follows The (default) markdown output of the source snippet above is as follows
````markdown ```@eval
# Rational numbers file = joinpath(@__DIR__, "src/generated/name.md")
str = "````markdown\n" * rstrip(read(file, String)) * "\n````"
In julia rational numbers can be constructed with the `//` operator. rm(file)
Lets define two rational numbers, `x` and `y`: Markdown.parse(str)
```@example name
x = 1//3
```
```@example name
y = 2//5
```
When adding `x` and `y` together we obtain a new rational number:
```@example name
z = x + y
``` ```
````
We note that lines starting with `#'` is printed as regular markdown, We note that lines starting with `#'` is printed as regular markdown,
and the code lines have been wrapped in `@example` blocks. and the code lines have been wrapped in `@example` blocks. We also note that
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).
Some of the output rendering can be controlled with keyword arguments to Some of the output rendering can be controlled with keyword arguments to
[`Literate.markdown`](@ref): [`Literate.markdown`](@ref):
@ -57,25 +35,8 @@ Literate.markdown
## [**4.2.** Notebook Output](@id Notebook-Output) ## [**4.2.** Notebook Output](@id Notebook-Output)
The (default) notebook output of the source snippet above is as follows The (default) notebook output of the source snippet can be seen here:
[notebook.ipynb](generated/notebook.ipynb).
```
│ # Rational numbers
│ In julia rational numbers can be constructed with the `//` operator.
│ Lets define two rational numbers, `x` and `y`:
In[1]: │ x = 1//3
Out[1]: │ 1//3
In[2]: │ y = 2//5
Out[2]: │ 2//5
│ When adding `x` and `y` together we obtain a new rational number:
In[3]: │ z = x + y
Out[3]: │ 11/15
```
We note that lines starting with `#'` is put in markdown cells, We note that lines starting with `#'` is put in markdown cells,
and the code lines have been put in code cells. By default the notebook and the code lines have been put in code cells. By default the notebook
@ -93,12 +54,11 @@ Literate.notebook
The (default) script output of the source snippet above is as follows The (default) script output of the source snippet above is as follows
```julia ```@eval
x = 1//3 file = joinpath(@__DIR__, "src/generated/outputformats.jl")
str = "```julia\n" * rstrip(read(file, String)) * "\n```"
y = 2//5 rm(file)
Markdown.parse(str)
z = x + y
``` ```
We note that lines starting with `#'` are removed and only the We note that lines starting with `#'` are removed and only the

Loading…
Cancel
Save