Skip to content

Commit 1c61b32

Browse files
committed
Reduce the PR down to minimal changes
1 parent def9568 commit 1c61b32

File tree

18 files changed

+1443
-150
lines changed

18 files changed

+1443
-150
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
**For upgrading:** To keep using the Markdown backend, refer to the [DocumenterMarkdown package][documentermarkdown]. That package might not immediately support the latest Documenter version, however.
99

1010
* ![Enhancement][badge-enhancement] The `ansicolor` keyword to `HTML()` now defaults to true, meaning that executed outputs from `@example`- and `@repl`-blocks are now by default colored (if they emit colored output). ([#1828][github-1828])
11+
* ![Enhancement][badge-enhancement] A more general API is now available to configure the remote repository URLs via the `repo` argument of `makedocs` by passing objects that are subtypes of `Remotes.Remote` and implement its interface (e.g. `Remotes.GitHub`). ([#1808][github-1808])
12+
* ![Enhancement][badge-enhancement] Broken issue references (i.e. links like `[#1234](@ref)`, but when Documenter is unable to determine the remote GitHub repository) now generate `:cross_references` errors that can be caught via the `strict` keyword. ([#1808][github-1808])
13+
14+
This is **potentially breaking** as it can cause previously working builds to fail if they are being run in strict mode. However, such builds were already leaving broken links in the generated documentation.
15+
16+
**For upgrading:** the best course to fix the build is to remove the offending `@ref` links. Alternatively, the `repo` argument to `makedocs` can be set to the appropriate `Remotes.Remote` object that implements the `Remotes.issueurl` function.
17+
18+
* ![Bugfix][badge-bugfix] Documenter now generates the correct source URLs for docstrings from other packages when the `repo` argument to `makedocs` is set (note: the source links to such docstrings only work if the external package is cloned from GitHub and added as a dev-dependency). However, this change **breaks** the case where the `repo` argument is used to override the main package/repository URL, assuming the repository is cloned from GitHub. ([#1808][github-1808])
1119

1220
## Version `v0.27.21`
1321

@@ -1067,6 +1075,7 @@
10671075
[github-1805]: https://github.com/JuliaDocs/Documenter.jl/pull/1805
10681076
[github-1806]: https://github.com/JuliaDocs/Documenter.jl/pull/1806
10691077
[github-1807]: https://github.com/JuliaDocs/Documenter.jl/pull/1807
1078+
[github-1808]: https://github.com/JuliaDocs/Documenter.jl/pull/1808
10701079
[github-1810]: https://github.com/JuliaDocs/Documenter.jl/issues/1810
10711080
[github-1811]: https://github.com/JuliaDocs/Documenter.jl/pull/1811
10721081
[github-1814]: https://github.com/JuliaDocs/Documenter.jl/issues/1814

docs/src/lib/internals/utilities.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33
```@autodocs
44
Modules = [Documenter.Utilities]
55
```
6+
7+
```@docs
8+
Remotes.URL
9+
Remotes.repofile
10+
```

docs/src/lib/public.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ DocMeta.getdocmeta
3131
DocMeta.setdocmeta!
3232
```
3333

34+
### Remotes
35+
36+
```@docs
37+
Documenter.Remotes
38+
Documenter.Remotes.GitHub
39+
```
40+
41+
The following types and functions and relevant when creating custom
42+
[`Remote`](@ref Documenter.Remotes.Remote) types:
43+
44+
```@docs
45+
Documenter.Remotes.Remote
46+
Documenter.Remotes.repourl
47+
Documenter.Remotes.fileurl
48+
Documenter.Remotes.issueurl
49+
```
50+
3451
## DocumenterTools
3552

3653
```@docs

src/CrossReferences.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import ..Documenter:
1313
Utilities.@docerror
1414

1515
using DocStringExtensions
16+
using .Utilities: Remotes
1617
import Markdown
1718

1819
"""
@@ -213,8 +214,13 @@ getsig(λ::Union{Function, DataType}, typesig) = Base.tuple_type_tail(which(λ,
213214
# -----------------------------
214215

215216
function issue_xref(link::Markdown.Link, num, meta, page, doc)
216-
link.url = isempty(doc.internal.remote) ? link.url :
217-
"https://github.com/$(doc.internal.remote)/issues/$num"
217+
# Update issue links starting with a hash, but only if our Remote supports it
218+
issue_url = Remotes.issueurl(doc.user.remote, num)
219+
if isnothing(issue_url)
220+
@docerror(doc, :cross_references, "unable to generate issue reference for '[`#$num`](@ref)' in $(Utilities.locrepr(page.source)).")
221+
else
222+
link.url = issue_url
223+
end
218224
end
219225

220226
end

src/Documenter.jl

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ include("CrossReferences.jl")
6161
include("DocChecks.jl")
6262
include("Writers/Writers.jl")
6363

64-
import .Utilities: Selectors, git
64+
import .Utilities: Selectors, Remotes, git
6565
import .Writers.HTMLWriter: HTML, asset
6666
import .Writers.HTMLWriter.RD: KaTeX, MathJax, MathJax2, MathJax3
6767
import .Writers.LaTeXWriter: LaTeX
6868

6969
# User Interface.
7070
# ---------------
71-
export makedocs, deploydocs, hide, doctest, DocMeta, asset,
71+
export makedocs, deploydocs, hide, doctest, DocMeta, asset, Remotes,
7272
KaTeX, MathJax, MathJax2, MathJax3
7373

7474
"""
@@ -158,23 +158,16 @@ makedocs(
158158
and so any docstring from the module `Documenter` that is not spliced into the generated
159159
documentation in `build` will raise a warning.
160160
161-
**`repo`** specifies a template for the "link to source" feature. If you are
162-
using GitHub, this is automatically generated from the remote. If you are using
163-
a different host, you can use this option to tell Documenter how URLs should be
164-
generated. The following placeholders will be replaced with the respective
165-
value of the generated link:
161+
**`repo`** specifies the browsable remote repository (e.g. on github.com). This is used for
162+
generating various remote links, such as the "source" links on docstrings. It can either
163+
be passed an object that implements the [`Remotes.Remote`](@ref) interface (e.g.
164+
[`Remotes.GitHub`](@ref)) or a template string. If a string is passed, it is interpreted
165+
according to the rules described in [`Remotes.URL`](@ref).
166166
167-
- `{commit}` Git branch or tag name, or commit hash
168-
- `{path}` Path to the file in the repository
169-
- `{line}` Line (or range of lines) in the source file
170-
171-
BitBucket, GitLab and Azure DevOps are supported along with GitHub, for example:
172-
173-
```julia
174-
makedocs(repo = \"https://gitlab.com/user/project/blob/{commit}{path}#{line}\") # GitLab
175-
makedocs(repo = \"https://dev.azure.com/org/project/_git/repo?path={path}&version={commit}{line}&lineStartColumn=1&lineEndColumn=1\") # Azure DevOps
176-
makedocs(repo = \"https://bitbucket.org/user/project/src/{commit}/{path}#lines-{line}\") # BitBucket
177-
```
167+
By default, the repository is assumed to be hosted on GitHub, and the remote URL is
168+
determined by first checking the URL of the `origin` Git remote, and then falling back to
169+
checking the `TRAVIS_REPO_SLUG` (for Travis CI) and `GITHUB_REPOSITORY` (for GitHub Actions)
170+
environment variables. If this automatic procedure fails, a warning is printed.
178171
179172
**`highlightsig`** enables or disables automatic syntax highlighting of leading, unlabeled
180173
code blocks in docstrings (as Julia code). For example, if your docstring begins with an

src/Documents.jl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import ..Documenter:
1616
Plugin,
1717
Writer
1818

19-
import ..Documenter.Utilities.Markdown2
19+
using ..Documenter.Utilities: Remotes, Markdown2
2020
using DocStringExtensions
2121
import Markdown
2222
using Unicode
@@ -244,7 +244,7 @@ struct User
244244
strict::Union{Bool,Symbol,Vector{Symbol}} # Throw an exception when any warnings are encountered.
245245
pages :: Vector{Any} # Ordering of document pages specified by the user.
246246
expandfirst::Vector{String} # List of pages that get "expanded" before others
247-
repo :: String # Template for URL to source code repo
247+
remote :: Union{Remotes.Remote,Nothing} # Remote Git repository information
248248
sitename:: String
249249
authors :: String
250250
version :: String # version string used in the version selector by default
@@ -257,7 +257,6 @@ Private state used to control the generation process.
257257
"""
258258
struct Internal
259259
assets :: String # Path where asset files will be copied to.
260-
remote :: String # The remote repo on github where this package is hosted.
261260
navtree :: Vector{NavNode} # A vector of top-level navigation items.
262261
navlist :: Vector{NavNode} # An ordered list of `NavNode`s that point to actual pages
263262
headers :: Anchors.AnchorMap # See `modules/Anchors.jl`. Tracks `Markdown.Header` objects.
@@ -300,7 +299,7 @@ function Document(plugins = nothing;
300299
modules :: Utilities.ModVec = Module[],
301300
pages :: Vector = Any[],
302301
expandfirst :: Vector = String[],
303-
repo :: AbstractString = "",
302+
repo :: Union{Remotes.Remote, AbstractString} = "",
304303
sitename :: AbstractString = "",
305304
authors :: AbstractString = "",
306305
version :: AbstractString = "",
@@ -320,6 +319,20 @@ function Document(plugins = nothing;
320319
version = "git:$(Utilities.get_commit_short(root))"
321320
end
322321

322+
remote = if isa(repo, AbstractString) && isempty(repo)
323+
# If the user does not provide the `repo` argument, we'll try to automatically
324+
# detect the remote repository by looking at the Git repository remote. This only
325+
# works if the repository is hosted on GitHub. If that fails, it falls back to
326+
# TRAVIS_REPO_SLUG.
327+
Utilities.getremote(root)
328+
elseif repo isa AbstractString
329+
# Use the old template string parsing logic if a string was passed.
330+
Remotes.URL(repo)
331+
else
332+
# Otherwise it should be some Remote object
333+
repo
334+
end
335+
323336
user = User(
324337
root,
325338
source,
@@ -336,7 +349,7 @@ function Document(plugins = nothing;
336349
strict,
337350
pages,
338351
expandfirst,
339-
repo,
352+
remote,
340353
sitename,
341354
authors,
342355
version,
@@ -345,7 +358,6 @@ function Document(plugins = nothing;
345358
)
346359
internal = Internal(
347360
Utilities.assetsdir(),
348-
Utilities.getremote(root),
349361
[],
350362
[],
351363
Anchors.AnchorMap(),

0 commit comments

Comments
 (0)