-
Notifications
You must be signed in to change notification settings - Fork 498
Tighter rules for referencing #2678
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
base: master
Are you sure you want to change the base?
Conversation
I think that accurately describes the current situation. It's a little bit unfortunate that the explicit link for a DocString is |
Yeah, I thought that too. However, I don't think it's ambiguous if we require that explicit header references are inside double quotes (it is supported at least: Documenter.jl/src/cross_references.jl Line 298 in 9bec14d
And for explicit:
The conditions are mutually exclusive this way. |
I made a little progress, but I realized that the rules are indeed ambiguous due to referencing headers by their id: [link](@ref someid)
[# Header](@id someid)
```@docs
someid
``` |
If there is an Otherwise, the rules in #2678 (comment) seem correct to me! As far as I can tell, this matches what we have documented, even if the implementation doesn't doesn't match. I'm actually surprised that the current implementation seems to be more.. uhm.. loose.. than I though it would be. What would be nice is to add some tests here (if feasible.. it can be tricky sometimes for this kind of stuff), and also clarify the docs (e.g. the table from the OP would be great to add to the docs probably). What might be good is to build the Julia manual with this PR before merging, just to see if any warnings crop up. |
Thank you for your input, Morten.
I see. The problem is though when the user makes a mistake in the id: See [link](@ref header-wrong)
# [Header](@id header-correct) In this case, Implicit references are unambiguous
That means if startswith(text, "#")
# process as an issue reference
elseif occursin(r"^`.+`$", text)
# process as a code reference
else
# process as a header reference
end For explicit references, we can allow and prefer backticks when referring to docstrings, as Michael pointed out. Then, the explicit references are unambiguous too:
leading to the decision if occursin(r"^\".+\"$", link)
# process as a header reference
elseif startswith(link, "#")
# process as an issue reference
elseif occursin(r"^`.+`$", link)
# process as a code reference
else
# process as a header reference via id
end The problem is backwards compatibility of code references. Right now,
in this order. So, we can extend the decision algorithm if occursin(r"^\".+\"$", link)
# process as a header reference
elseif startswith(link, "#")
# process as an issue reference
elseif occursin(r"^`.+`$", link)
# process as a code reference
else
# process as a header reference via id if there is such a header
# and otherwise, process as a code reference
end However, there's that problem with if occursin(r"^\".+\"$", link)
# process as a header reference
elseif startswith(link, "#")
# process as an issue reference
elseif occursin(r"^`.+`$", link)
# process as a code reference
else
if link consists of multiple dash-delimited words
# process as a header reference via id
else
# process as a header reference via id if there is such a header
# and otherwise, process as a code reference
end
end I don't think that many people try to use the explicit reference After some time, when breaking change is permitted, we can just drop this complicated logic in favor of the simple one above. How does that sound? |
This is an attempt to clarify the matching criteria for cross-references. I am not very familiar with Documenter's code base, so I am sure the code could be improved, but I am submitting the PR as it is to see if there's broader support for it.
Essentially, the goal is to respect the following rules for references:
[Header name](@ref)
[link](@ref "Header name")
[#12345](@ref)
[link](@ref #12345)
[`Module.func`](@ref)
[link](@ref Module.func)
It means that linking
[Nonexistent header](@ref)
will be recognized as a link to a header named "Nonexistent header", and never as link to a docstring forNonexistent-header
(ref. #2677).If this direction seems promising, I'd like to get feedback on how to improve the code, especially
linkcontent
.