Browse Source

try to fix links

pull/1/head
Fredrik Ekre 8 years ago
parent
commit
98d31ef42d
  1. 1
      .gitignore
  2. 21
      examples/example.jl
  3. 2
      src/Documenter.jl
  4. 22
      src/Examples.jl

1
.gitignore vendored

@ -1,3 +1,4 @@
*.jl.cov *.jl.cov
*.jl.*.cov *.jl.*.cov
*.jl.mem *.jl.mem
*.DS_Store

21
examples/example.jl

@ -1,18 +1,13 @@
#' # **7.** Example #' # **7.** Example
#' #'
#' *Output generated with Examples.jl based on #' This is an example for Examples.jl.
#' [this](../../../examples/example.jl) source file.* #' 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
#' This is an example source file for input to Examples.jl. #' generated notebook can be found here:
#' #' [`example.ipynb`](@__NBVIEWER__ROOT_URL__generated/example.ipynb), and the
#md #' If you are reading this you are seeing the markdown output #' plain script output can be found here: [`example.jl`](./example.jl).
#md #' generated from the source file, here you can see the corresponding
#md #' notebook output: [example.ipynb](./example.ipynb) #' ### Rational numbers in Julia
#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
#' Rational number in julia can be constructed with the `//` operator: #' Rational number in julia can be constructed with the `//` operator:
x = 1//3 x = 1//3

2
src/Documenter.jl

@ -2,6 +2,8 @@
# (https://github.com/JuliaDocs/Documenter.jl), see LICENSE.md for license # (https://github.com/JuliaDocs/Documenter.jl), see LICENSE.md for license
module Documenter module Documenter
using Compat: stdout, stderr, Cvoid
@static if VERSION < v"0.7.0-DEV.3951" @static if VERSION < v"0.7.0-DEV.3951"
link_pipe!(pipe; reader_supports_async = true, writer_supports_async = true) = 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) Base.link_pipe(pipe, julia_only_read = reader_supports_async, julia_only_write = writer_supports_async)

22
src/Examples.jl

@ -217,14 +217,18 @@ function markdown(inputfile, outputdir; preprocess = identity, postprocess = ide
# run some Documenter specific things # run some Documenter specific things
if documenter if documenter
# change the Edit on GitHub link # change the Edit on GitHub link
pkg = "Examples"
content = """ content = """
#' ```@meta #' ```@meta
#' EditURL = "$(relpath(inputfile, outputdir))" #' EditURL = "@__REPO_ROOT_URL__$(relpath(inputfile, Pkg.dir(pkg)))"
#' ``` #' ```
""" * content """ * content
end end
# fix urls to point to correct file
content = fixlinks(content)
# create the markdown file # create the markdown file
chunks = parse(content) chunks = parse(content)
iomd = IOBuffer() iomd = IOBuffer()
@ -314,6 +318,9 @@ function notebook(inputfile, outputdir; preprocess = identity, postprocess = ide
content = replace(content, repl) content = replace(content, repl)
end end
# fix urls to point to correct file
content = fixlinks(content)
# run some Documenter specific things # run some Documenter specific things
if documenter # TODO: safe to do this always? if documenter # TODO: safe to do this always?
# remove documenter style `@ref`s and `@id`s # remove documenter style `@ref`s and `@id`s
@ -453,4 +460,17 @@ function execute_notebook(nb)
nb nb
end 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 end # module

Loading…
Cancel
Save