diff --git a/.gitignore b/.gitignore index 8c960ec..8ee819d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.jl.cov *.jl.*.cov *.jl.mem +*.DS_Store \ No newline at end of file diff --git a/examples/example.jl b/examples/example.jl index 0c7f772..b4ecdcf 100644 --- a/examples/example.jl +++ b/examples/example.jl @@ -1,18 +1,13 @@ #' # **7.** Example #' -#' *Output generated with Examples.jl based on -#' [this](../../../examples/example.jl) source file.* -#' -#' This is an example source file for input to Examples.jl. -#' -#md #' If you are reading this you are seeing the markdown output -#md #' generated from the source file, here you can see the corresponding -#md #' notebook output: [example.ipynb](./example.ipynb) -#nb #' If you are reading this you are seeing the notebook output -#nb #' generated from the source file, here you can see the corresponding -#nb #' markdown output: [example.md](./example.md) - -#' ## Rational numbers in Julia +#' This is an example for Examples.jl. +#' The source file can be found [here](@__REPO_ROOT_URL__examples/example.jl). +#' The generated markdown can be found here: [`example.md`](./example.md), the +#' generated notebook can be found here: +#' [`example.ipynb`](@__NBVIEWER__ROOT_URL__generated/example.ipynb), and the +#' plain script output can be found here: [`example.jl`](./example.jl). + +#' ### Rational numbers in Julia #' Rational number in julia can be constructed with the `//` operator: x = 1//3 diff --git a/src/Documenter.jl b/src/Documenter.jl index ab0bd6a..8e7887f 100644 --- a/src/Documenter.jl +++ b/src/Documenter.jl @@ -2,6 +2,8 @@ # (https://github.com/JuliaDocs/Documenter.jl), see LICENSE.md for license module Documenter +using Compat: stdout, stderr, Cvoid + @static if VERSION < v"0.7.0-DEV.3951" link_pipe!(pipe; reader_supports_async = true, writer_supports_async = true) = Base.link_pipe(pipe, julia_only_read = reader_supports_async, julia_only_write = writer_supports_async) diff --git a/src/Examples.jl b/src/Examples.jl index 4aeb342..b9a3568 100644 --- a/src/Examples.jl +++ b/src/Examples.jl @@ -217,14 +217,18 @@ function markdown(inputfile, outputdir; preprocess = identity, postprocess = ide # run some Documenter specific things if documenter # change the Edit on GitHub link + pkg = "Examples" content = """ #' ```@meta - #' EditURL = "$(relpath(inputfile, outputdir))" + #' EditURL = "@__REPO_ROOT_URL__$(relpath(inputfile, Pkg.dir(pkg)))" #' ``` """ * content end + # fix urls to point to correct file + content = fixlinks(content) + # create the markdown file chunks = parse(content) iomd = IOBuffer() @@ -314,6 +318,9 @@ function notebook(inputfile, outputdir; preprocess = identity, postprocess = ide content = replace(content, repl) end + # fix urls to point to correct file + content = fixlinks(content) + # run some Documenter specific things if documenter # TODO: safe to do this always? # remove documenter style `@ref`s and `@id`s @@ -453,4 +460,17 @@ function execute_notebook(nb) nb end +function fixlinks(content; commit = "master") + # replace @__REPO__ to master/commit + repo = get(ENV, "TRAVIS_REPO_SLUG", "") + root_url = "https://github.com/$(repo)/blob/$(commit)/" + content = replace(content, "@__REPO_ROOT_URL__" => root_url) + # replace @__NBVIEWER__ to latest or version directory + folder = "latest" + branch = "gh-pages" + nbviewer_root_url = "https://nbviewer.jupyter.org/github/$(repo)/blob/$(branch)/$(folder)/" + content = replace(content, "@__NBVIEWER__ROOT_URL__" => nbviewer_root_url) + return content +end + end # module