Browse Source

Add at__BINDER_ROOT_URL__ macro to expand to a binder link, fixes #46.

pull/57/head
Fredrik Ekre 7 years ago
parent
commit
e3c878aa32
  1. 1
      docs/make.jl
  2. 12
      docs/src/fileformat.md
  3. 14
      examples/example.jl
  4. 6
      src/Literate.jl

1
docs/make.jl

@ -33,6 +33,7 @@ end @@ -33,6 +33,7 @@ end
makedocs(
format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true"),
modules = [Literate],
sitename = "Literate.jl",
pages = Any[

12
docs/src/fileformat.md

@ -108,3 +108,15 @@ The following convenience "macros" are always expanded: @@ -108,3 +108,15 @@ The following convenience "macros" are always expanded:
where `folder` is the folder that `Documenter.deploydocs` deploys too.
This can be used if you want a link that opens the generated notebook in
[http://nbviewer.jupyter.org/](http://nbviewer.jupyter.org/).
- `@__BINDER_ROOT_URL__`
expands to
`https://mybinder.org/v2/gh/$(ENV["TRAVIS_REPO_SLUG"])/$(branch)?filepath=$(folder)/`
where `branch`/`folder` is the branch and folder where `Documenter.deploydocs`
deploys too. This can be used if you want a link that opens the generated notebook in
[https://mybinder.org/](https://mybinder.org/).
To add a binder-badge in e.g. the HTML output you can use:
```
[![Binder](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__path/to/notebook.inpynb)
```

14
examples/example.jl

@ -1,13 +1,19 @@ @@ -1,13 +1,19 @@
# # **7.** Example
#
#md # [![](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__generated/example.inpynb)
#md # [![](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__generated/example.ipynb)
#
# This is an example generated with Literate based on this
# source file: [`example.jl`](@__REPO_ROOT_URL__examples/example.jl).
# You are seeing the
#md # html-output which Documenter have generated based on a markdown
#md # HTML-output which Documenter have generated based on a markdown
#md # file generated with Literate. The corresponding notebook
#md # can be found here: [`example.ipynb`](@__NBVIEWER_ROOT_URL__generated/example.ipynb),
#nb # generated notebook output. The corresponding markdown (html) output
#nb # can be found here: [`example.html`](https://fredrikekre.github.io/Literate.jl/latest/generated/example.html),
#md # can be viewed in [nbviewer](http://nbviewer.jupyter.org/) here:
#md # [`example.ipynb`](@__NBVIEWER_ROOT_URL__generated/example.ipynb),
#md # and opened in [binder](https://mybinder.org/) here:
#md # [`example.ipynb`](@__BINDER_ROOT_URL__generated/example.ipynb),
#nb # generated notebook output. The corresponding markdown (HTML) output
#nb # can be found here: [`example.html`](https://fredrikekre.github.io/Literate.jl/dev/generated/example.html),
# and the plain script output can be found here: [`example.jl`](./example.jl).
# It is recommended to have the [source file](@__REPO_ROOT_URL__examples/example.jl)

6
src/Literate.jl

@ -182,10 +182,14 @@ function replace_default(content, sym; @@ -182,10 +182,14 @@ function replace_default(content, sym;
repo_root_url = "https://github.com/$(travis_repo_slug)/blob/$(commit)/"
push!(repls, "@__REPO_ROOT_URL__" => repo_root_url)
## replace @__NBVIEWER_ROOT_URL__ to latest or version directory
## replace @__NBVIEWER_ROOT_URL__ to dev or version directory
nbviewer_root_url = "https://nbviewer.jupyter.org/github/$(travis_repo_slug)/blob/$(branch)/$(folder)/"
push!(repls, "@__NBVIEWER_ROOT_URL__" => nbviewer_root_url)
## replace $__BINDER_ROOT_URL__ to dev or version directory
binder_root_url = "https://mybinder.org/v2/gh/$(travis_repo_slug)/$(branch)?filepath=$(folder)/"
push!(repls, "@__BINDER_ROOT_URL__" => binder_root_url)
if get(ENV, "HAS_JOSH_K_SEAL_OF_APPROVAL", "") != "true"
@info "not running on Travis, skipping links will not be correct."
end

Loading…
Cancel
Save