diff --git a/docs/make.jl b/docs/make.jl index 12cfb0c..4bae92d 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -33,6 +33,7 @@ end makedocs( + format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true"), modules = [Literate], sitename = "Literate.jl", pages = Any[ diff --git a/docs/src/fileformat.md b/docs/src/fileformat.md index 8e7a49e..fbc0885 100644 --- a/docs/src/fileformat.md +++ b/docs/src/fileformat.md @@ -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) + ``` diff --git a/examples/example.jl b/examples/example.jl index feccdf0..d86aefe 100644 --- a/examples/example.jl +++ b/examples/example.jl @@ -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) diff --git a/src/Literate.jl b/src/Literate.jl index f2ac4ca..a5d46f3 100644 --- a/src/Literate.jl +++ b/src/Literate.jl @@ -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