Skip to content

Using @ref with non-existent multiple-word header names #2677

@barucden

Description

@barucden

Consider the following markdown documentation:

[Two words](@ref).

[Different words](@ref).

## Two words

The first link is correctly interpreted as a reference to the header "Two words".

The second link is more problematic. In the process of resolving the link, Documenter creates the slug Different-words for it, and since there is no header named "Different words", Documenter will treat Different-words to be a link to a docstring Different - words (i.e., invocation of Base.:(-)). In most code bases, the user gets a warning

┌ Warning: Cannot resolve @ref for md"[Different words](@ref)" in src/index.md.
│ - No docstring found in doc for binding `Base.-`.
└ @ Documenter ~/julia/Documenter.jl/src/utilities/utilities.jl:49

However, in julia's codebase, there is a docstring for Base.:(-) and so [Different words](@ref) would be resolved as a link to that function's docstring. This behavior is not optimal because it falsely succeeds in resolving non-existent links (see JuliaLang/julia#58073).

A quick-and-dirty solution would be to add the following at the beginning of find_docref:

# Check if the slug matches multiple dash-delimited words
if occursin(r"^\w+(-\w+){1,}$", code)
    return (
        error = "unable to get the binding for `$code` in module $(mod)",
        exception = nothing,
    )
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions