Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show more context in invalid local link warnings #2100

Merged
merged 3 commits into from Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -79,6 +79,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Added the ability to expand/collapse individual as well as all docstrings. (#1393, #2078)

* Invalid local link warnings during HTML rendering now print a bit more context, helping in pinpointing the offending link. (#2100)

### Fixed

* 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)
Expand Down
22 changes: 10 additions & 12 deletions src/html/HTMLWriter.jl
Expand Up @@ -1162,7 +1162,7 @@ end

function render_navbar(ctx, navnode, edit_page_link::Bool)
@tags div header nav ul li a span

navbar_left = div[".docs-left"]
# Hamburger on mobile
push!(navbar_left.nodes, a[
Expand Down Expand Up @@ -1944,7 +1944,7 @@ domify(dctx::DCtx, node::Node, ::MarkdownAST.ThematicBreak) = Tag(:hr)()
function domify(dctx::DCtx, node::Node, i::MarkdownAST.Image)
ctx, navnode = dctx.ctx, dctx.navnode
alt = mdflatten(node.children)
url = fixlink(dctx, i)
url = fixlink(dctx, node, i)
# function mdconvert(i::Markdown.Image, parent; kwargs...)
# TODO: Implement .title
@tags video img a
Expand All @@ -1969,7 +1969,7 @@ domify(dctx::DCtx, node::Node, m::MarkdownAST.LineBreak) = Tag(:br)()

function domify(dctx::DCtx, node::Node, link::MarkdownAST.Link)
droplinks = dctx.droplinks
url = fixlink(dctx, link)
url = fixlink(dctx, node, link)
# function mdconvert(link::Markdown.Link, parent; droplinks=false, kwargs...)
link_text = domify(dctx, node.children)
droplinks ? link_text : Tag(:a)[:href => url](link_text)
Expand Down Expand Up @@ -2169,12 +2169,11 @@ function domify(dctx::DCtx, node::Node, d::Dict{MIME,Any})
end
end

# fixlinks!
# fixlink
# ------------------------------------------------------------------------------

function fixlink(dctx::DCtx, link::MarkdownAST.Link)
function fixlink(dctx::DCtx, node::Node, link::MarkdownAST.Link)
ctx, navnode = dctx.ctx, dctx.navnode
# function fixlinks!(ctx, navnode, link::Markdown.Link)
link_url = link.destination
Documenter.isabsurl(link_url) && return link_url

Expand All @@ -2187,7 +2186,7 @@ function fixlink(dctx::DCtx, link::MarkdownAST.Link)

s = split(link_url, "#", limit = 2)
if Sys.iswindows() && ':' in first(s)
@warn "invalid local link: colons not allowed in paths on Windows in $(Documenter.locrepr(navnode.page))" link_url
@warn "invalid local link: colons not allowed in paths on Windows in $(Documenter.locrepr(navnode.page))" link=node
return link_url
end
path = normpath(joinpath(dirname(navnode.page), first(s)))
Expand All @@ -2200,22 +2199,21 @@ function fixlink(dctx::DCtx, link::MarkdownAST.Link)
# provided files or generated by code examples)
path = relhref(get_url(ctx, navnode), path)
else
@warn "invalid local link: unresolved path in $(Documenter.locrepr(navnode.page))" link_url
@warn "invalid local link: unresolved path in $(Documenter.locrepr(navnode.page))" link=node
end

# Replace any backslashes in links, if building the docs on Windows
path = replace(path, '\\' => '/')
return (length(s) > 1) ? "$path#$(last(s))" : String(path)
end

function fixlink(dctx::DCtx, img::MarkdownAST.Image)
function fixlink(dctx::DCtx, node::Node, img::MarkdownAST.Image)
ctx, navnode = dctx.ctx, dctx.navnode
# function fixlinks!(ctx, navnode, img::Markdown.Image)
img_url = img.destination
Documenter.isabsurl(img_url) && return img_url

if Sys.iswindows() && ':' in img_url
@warn "invalid local image: colons not allowed in paths on Windows in $(Documenter.locrepr(navnode.page))" img_url
@warn "invalid local image: colons not allowed in paths on Windows in $(Documenter.locrepr(navnode.page))" link=node
return img_url
end

Expand All @@ -2225,7 +2223,7 @@ function fixlink(dctx::DCtx, img::MarkdownAST.Image)
# Replace any backslashes in links, if building the docs on Windows
return replace(path, '\\' => '/')
else
@warn "invalid local image: unresolved path in $(Documenter.locrepr(navnode.page))" link = img_url
@warn "invalid local image: unresolved path in $(Documenter.locrepr(navnode.page))" link=node
return img_url
end
end
Expand Down