Skip to content

Commit 2f23a05

Browse files
authored
Use Hexdocs format in :otp anchors (#1908)
1 parent f4a46cb commit 2f23a05

File tree

6 files changed

+37
-45
lines changed

6 files changed

+37
-45
lines changed

lib/ex_doc/autolink.ex

+6-14
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ defmodule ExDoc.Autolink do
430430

431431
case {kind, visibility} do
432432
{_kind, :public} ->
433-
fragment(tool(module, config), kind, name, arity)
433+
fragment(kind, name, arity)
434434

435435
{:function, _visibility} ->
436436
case config.language.try_autoimported_function(name, arity, mode, config, original_text) do
@@ -464,22 +464,14 @@ defmodule ExDoc.Autolink do
464464
end
465465
end
466466

467-
def fragment(tool, kind, nil, arity) do
468-
fragment(tool, kind, "nil", arity)
467+
def fragment(kind, nil, arity) do
468+
fragment(kind, "nil", arity)
469469
end
470470

471-
def fragment(:ex_doc, kind, name, arity) do
471+
def fragment(kind, name, arity) do
472472
"#" <> prefix(kind) <> "#{encode_fragment_name(name)}/#{arity}"
473473
end
474474

475-
def fragment(:otp, kind, name, arity) do
476-
case kind do
477-
:function -> "##{encode_fragment_name(name)}-#{arity}"
478-
:callback -> "#Module:#{encode_fragment_name(name)}-#{arity}"
479-
:type -> "#type-#{encode_fragment_name(name)}"
480-
end
481-
end
482-
483475
defp encode_fragment_name(name) when is_atom(name) do
484476
encode_fragment_name(Atom.to_string(name))
485477
end
@@ -503,10 +495,10 @@ defmodule ExDoc.Autolink do
503495
tool = tool(module, config)
504496

505497
if same_module? do
506-
fragment(tool, kind, name, arity)
498+
fragment(kind, name, arity)
507499
else
508500
url = string_app_module_url(original_text, tool, module, nil, config)
509-
url && url <> fragment(tool, kind, name, arity)
501+
url && url <> fragment(kind, name, arity)
510502
end
511503

512504
{:regular_link, module_visibility, :undefined}

lib/ex_doc/language/erlang.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,12 @@ defmodule ExDoc.Language.Erlang do
431431
end
432432

433433
defp final_url({kind, name, arity}, _config) do
434-
Autolink.fragment(:ex_doc, kind, name, arity)
434+
Autolink.fragment(kind, name, arity)
435435
end
436436

437437
defp final_url({kind, module, name, arity}, config) do
438438
tool = Autolink.tool(module, config)
439-
Autolink.app_module_url(tool, module, Autolink.fragment(tool, kind, name, arity), config)
439+
Autolink.app_module_url(tool, module, Autolink.fragment(kind, name, arity), config)
440440
end
441441

442442
@impl true

test/ex_doc/formatter/html/erlang_test.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ defmodule ExDoc.Formatter.HTML.ErlangTest do
3636
~s|-spec</span> foo(<a href=\"#t:t/0\">t</a>()) -&gt; <a href=\"#t:t/0\">t</a>().|
3737

3838
assert html =~
39-
~s|-type</span> t() :: <a href=\"https://www.erlang.org/doc/man/erlang.html#type-atom\">atom</a>().|
39+
~s|-type</span> t() :: <a href=\"https://www.erlang.org/doc/man/erlang.html#t:atom/0\">atom</a>().|
4040

4141
assert html =~
42-
~s|-type</span> t2() :: #rec{k1 :: <a href=\"https://www.erlang.org/doc/man/uri_string.html#type-uri_string\">uri_string:uri_string</a>(), k2 :: <a href=\"https://www.erlang.org/doc/man/uri_string.html#type-uri_string\">uri_string:uri_string</a>() \| undefined}.|
42+
~s|-type</span> t2() :: #rec{k1 :: <a href=\"https://www.erlang.org/doc/man/uri_string.html#t:uri_string/0\">uri_string:uri_string</a>(), k2 :: <a href=\"https://www.erlang.org/doc/man/uri_string.html#t:uri_string/0\">uri_string:uri_string</a>() \| undefined}.|
4343
end
4444

4545
defp generate_docs(c) do

test/ex_doc/language/elixir_test.exs

+5-5
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ defmodule ExDoc.Language.ElixirTest do
9999

100100
test "erlang stdlib function" do
101101
assert autolink_doc("`:lists.all/2`") ==
102-
~s|<a href="https://www.erlang.org/doc/man/lists.html#all-2"><code class="inline">:lists.all/2</code></a>|
102+
~s|<a href="https://www.erlang.org/doc/man/lists.html#all/2"><code class="inline">:lists.all/2</code></a>|
103103
end
104104

105105
test "local function" do
@@ -150,7 +150,7 @@ defmodule ExDoc.Language.ElixirTest do
150150

151151
test "erlang callback" do
152152
assert autolink_doc("`c::gen_server.handle_call/3`") ==
153-
~s|<a href="https://www.erlang.org/doc/man/gen_server.html#Module:handle_call-3"><code class="inline">:gen_server.handle_call/3</code></a>|
153+
~s|<a href="https://www.erlang.org/doc/man/gen_server.html#c:handle_call/3"><code class="inline">:gen_server.handle_call/3</code></a>|
154154
end
155155

156156
test "elixir type" do
@@ -171,7 +171,7 @@ defmodule ExDoc.Language.ElixirTest do
171171

172172
test "erlang type" do
173173
assert autolink_doc("`t::array.array/0`") ==
174-
~s|<a href="https://www.erlang.org/doc/man/array.html#type-array"><code class="inline">:array.array/0</code></a>|
174+
~s|<a href="https://www.erlang.org/doc/man/array.html#t:array/0"><code class="inline">:array.array/0</code></a>|
175175
end
176176

177177
test "special forms" do
@@ -207,7 +207,7 @@ defmodule ExDoc.Language.ElixirTest do
207207
~s|<a href="https://www.erlang.org/doc/man/lists.html">custom text</a>|
208208

209209
assert autolink_doc("[custom text](`:lists.all/2`)") ==
210-
~s|<a href="https://www.erlang.org/doc/man/lists.html#all-2">custom text</a>|
210+
~s|<a href="https://www.erlang.org/doc/man/lists.html#all/2">custom text</a>|
211211
end
212212

213213
test "mix task" do
@@ -450,7 +450,7 @@ defmodule ExDoc.Language.ElixirTest do
450450

451451
test "Erlang stdlib types" do
452452
assert autolink_spec(quote(do: t() :: :sets.set())) ==
453-
~s[t() :: <a href="https://www.erlang.org/doc/man/sets.html#type-set">:sets.set</a>()]
453+
~s[t() :: <a href="https://www.erlang.org/doc/man/sets.html#t:set/0">:sets.set</a>()]
454454
end
455455

456456
test "escape special HTML characters" do

test/ex_doc/language/erlang_test.exs

+19-19
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ defmodule ExDoc.Language.ErlangTest do
8484

8585
test "OTP function", c do
8686
assert autolink_edoc("{@link array:new/0}", c) ==
87-
~s|<a href="https://www.erlang.org/doc/man/array.html#new-0"><code>array:new/0</code></a>|
87+
~s|<a href="https://www.erlang.org/doc/man/array.html#new/0"><code>array:new/0</code></a>|
8888
end
8989

9090
test "OTP function when generating OTP docs", c do
@@ -99,12 +99,12 @@ defmodule ExDoc.Language.ErlangTest do
9999

100100
test "ERTS function", c do
101101
assert autolink_edoc("{@link zlib:gunzip/1}", c) ==
102-
~s|<a href="https://www.erlang.org/doc/man/zlib.html#gunzip-1"><code>zlib:gunzip/1</code></a>|
102+
~s|<a href="https://www.erlang.org/doc/man/zlib.html#gunzip/1"><code>zlib:gunzip/1</code></a>|
103103
end
104104

105105
test "app function", c do
106106
assert autolink_edoc("{@link //stdlib/array:new/0}", c) ==
107-
~s|<a href="https://www.erlang.org/doc/man/array.html#new-0"><code>array:new/0</code></a>|
107+
~s|<a href="https://www.erlang.org/doc/man/array.html#new/0"><code>array:new/0</code></a>|
108108
end
109109

110110
test "external function", c do
@@ -124,12 +124,12 @@ defmodule ExDoc.Language.ErlangTest do
124124

125125
test "OTP type", c do
126126
assert autolink_edoc("{@link array:array()}", c) ==
127-
~s|<a href="https://www.erlang.org/doc/man/array.html#type-array"><code>array:array()</code></a>|
127+
~s|<a href="https://www.erlang.org/doc/man/array.html#t:array/0"><code>array:array()</code></a>|
128128
end
129129

130130
test "app type", c do
131131
assert autolink_edoc("{@link //stdlib/array:array()}", c) ==
132-
~s|<a href="https://www.erlang.org/doc/man/array.html#type-array"><code>array:array()</code></a>|
132+
~s|<a href="https://www.erlang.org/doc/man/array.html#t:array/0"><code>array:array()</code></a>|
133133
end
134134

135135
@myList (if :erlang.system_info(:otp_release) >= ~c"27" do
@@ -310,7 +310,7 @@ defmodule ExDoc.Language.ErlangTest do
310310

311311
test "function in module autoimport using slash", c do
312312
assert autolink_doc("`node/0`", c) ==
313-
~s|<a href="https://www.erlang.org/doc/man/erlang.html#node-0"><code class="inline">node/0</code></a>|
313+
~s|<a href="https://www.erlang.org/doc/man/erlang.html#node/0"><code class="inline">node/0</code></a>|
314314
end
315315

316316
test "type in module autoimport", c do
@@ -320,7 +320,7 @@ defmodule ExDoc.Language.ErlangTest do
320320

321321
test "type in module autoimport using slash", c do
322322
assert autolink_doc("`t:integer/0`", c) ==
323-
~s|<a href="https://www.erlang.org/doc/man/erlang.html#type-integer"><code class="inline">integer/0</code></a>|
323+
~s|<a href="https://www.erlang.org/doc/man/erlang.html#t:integer/0"><code class="inline">integer/0</code></a>|
324324
end
325325

326326
test "bad function in module code", c do
@@ -335,7 +335,7 @@ defmodule ExDoc.Language.ErlangTest do
335335

336336
test "linking to auto-imported nil works", c do
337337
assert autolink_doc("[`[]`](`t:nil/0`)", c) ==
338-
~s|<a href="https://www.erlang.org/doc/man/erlang.html#type-nil"><code class="inline">[]</code></a>|
338+
~s|<a href="https://www.erlang.org/doc/man/erlang.html#t:nil/0"><code class="inline">[]</code></a>|
339339
end
340340

341341
test "linking to local nil works", c do
@@ -543,7 +543,7 @@ defmodule ExDoc.Language.ErlangTest do
543543

544544
test "OTP function", c do
545545
assert autolink_extra("`lists:reverse/1`", c) ==
546-
~s|<a href="https://www.erlang.org/doc/man/lists.html#reverse-1"><code class="inline">lists:reverse/1</code></a>|
546+
~s|<a href="https://www.erlang.org/doc/man/lists.html#reverse/1"><code class="inline">lists:reverse/1</code></a>|
547547
end
548548

549549
test "type", c do
@@ -553,7 +553,7 @@ defmodule ExDoc.Language.ErlangTest do
553553

554554
test "OTP type", c do
555555
assert autolink_extra("`t:array:array/0`", c) ==
556-
~s|<a href="https://www.erlang.org/doc/man/array.html#type-array"><code class="inline">array:array/0</code></a>|
556+
~s|<a href="https://www.erlang.org/doc/man/array.html#t:array/0"><code class="inline">array:array/0</code></a>|
557557
end
558558

559559
test "module", c do
@@ -684,9 +684,9 @@ defmodule ExDoc.Language.ErlangTest do
684684

685685
test "spec when fun is called record", c do
686686
assert autolink_spec("-spec record(module()) -> [[{module(), atom()}]].", c) ==
687-
~s|record(<a href="https://www.erlang.org/doc/man/erlang.html#type-module">module</a>())| <>
688-
~s| -> [[{<a href="https://www.erlang.org/doc/man/erlang.html#type-module">module</a>(),| <>
689-
~s| <a href="https://www.erlang.org/doc/man/erlang.html#type-atom">atom</a>()}]].|
687+
~s|record(<a href="https://www.erlang.org/doc/man/erlang.html#t:module/0">module</a>())| <>
688+
~s| -> [[{<a href="https://www.erlang.org/doc/man/erlang.html#t:module/0">module</a>(),| <>
689+
~s| <a href="https://www.erlang.org/doc/man/erlang.html#t:atom/0">atom</a>()}]].|
690690
end
691691

692692
test "callback", c do
@@ -724,7 +724,7 @@ defmodule ExDoc.Language.ErlangTest do
724724
~S"-spec foo() -> #{atom() := sets:set(integer()), float() => t()}.",
725725
c
726726
) ==
727-
~S|foo() -> #{<a href="https://www.erlang.org/doc/man/erlang.html#type-atom">atom</a>() := <a href="https://www.erlang.org/doc/man/sets.html#type-set">sets:set</a>(<a href="https://www.erlang.org/doc/man/erlang.html#type-integer">integer</a>()), <a href="https://www.erlang.org/doc/man/erlang.html#type-float">float</a>() => <a href="#t:t/0">t</a>()}.|
727+
~S|foo() -> #{<a href="https://www.erlang.org/doc/man/erlang.html#t:atom/0">atom</a>() := <a href="https://www.erlang.org/doc/man/sets.html#t:set/1">sets:set</a>(<a href="https://www.erlang.org/doc/man/erlang.html#t:integer/0">integer</a>()), <a href="https://www.erlang.org/doc/man/erlang.html#t:float/0">float</a>() => <a href="#t:t/0">t</a>()}.|
728728
end
729729

730730
test "vars", c do
@@ -744,12 +744,12 @@ defmodule ExDoc.Language.ErlangTest do
744744

745745
test "record - one field", c do
746746
assert autolink_spec(~s"-spec foo() -> #x{x :: atom()} | t().", c) ==
747-
~s[foo() -> #x{x :: <a href="https://www.erlang.org/doc/man/erlang.html#type-atom">atom</a>()} | <a href="#t:t/0">t</a>().]
747+
~s[foo() -> #x{x :: <a href="https://www.erlang.org/doc/man/erlang.html#t:atom/0">atom</a>()} | <a href="#t:t/0">t</a>().]
748748
end
749749

750750
test "record - two fields", c do
751751
assert autolink_spec(~s"-spec foo() -> #x{x :: atom(), y :: sets:set(integer())} | t().", c) ==
752-
~s[foo() -> #x{x :: <a href="https://www.erlang.org/doc/man/erlang.html#type-atom">atom</a>(), y :: <a href="https://www.erlang.org/doc/man/sets.html#type-set">sets:set</a>(<a href="https://www.erlang.org/doc/man/erlang.html#type-integer">integer</a>())} | <a href="#t:t/0">t</a>().]
752+
~s[foo() -> #x{x :: <a href="https://www.erlang.org/doc/man/erlang.html#t:atom/0">atom</a>(), y :: <a href="https://www.erlang.org/doc/man/sets.html#t:set/1">sets:set</a>(<a href="https://www.erlang.org/doc/man/erlang.html#t:integer/0">integer</a>())} | <a href="#t:t/0">t</a>().]
753753
end
754754

755755
test "record - two fields, known types", c do
@@ -789,12 +789,12 @@ defmodule ExDoc.Language.ErlangTest do
789789

790790
test "OTP type", c do
791791
assert autolink_spec(~S"-spec foo() -> sets:set().", c) ==
792-
~s|foo() -> <a href="https://www.erlang.org/doc/man/sets.html#type-set">sets:set</a>().|
792+
~s|foo() -> <a href="https://www.erlang.org/doc/man/sets.html#t:set/0">sets:set</a>().|
793793
end
794794

795795
test "OTP private type", c do
796796
assert autolink_spec(~S"-spec foo() -> array:array_indx().", c) ==
797-
~s|foo() -> <a href="https://www.erlang.org/doc/man/array.html#type-array_indx">array:array_indx</a>().|
797+
~s|foo() -> <a href="https://www.erlang.org/doc/man/array.html#t:array_indx/0">array:array_indx</a>().|
798798
end
799799

800800
test "skip typespec name", c do
@@ -820,7 +820,7 @@ defmodule ExDoc.Language.ErlangTest do
820820
test "bad remote type", c do
821821
assert warn(fn ->
822822
assert autolink_spec(~S"-spec foo() -> bad:bad(atom()).", c, warnings: :send) ==
823-
~s|foo() -> bad:bad(<a href="https://www.erlang.org/doc/man/erlang.html#type-atom">atom</a>()).|
823+
~s|foo() -> bad:bad(<a href="https://www.erlang.org/doc/man/erlang.html#t:atom/0">atom</a>()).|
824824
end) =~ ~s|references type "bad:bad/1" but it is undefined or private|
825825
end
826826
end

test/ex_doc/retriever/erlang_test.exs

+3-3
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ defmodule ExDoc.Retriever.ErlangTest do
415415
assert DocAST.to_string(function1.doc) =~ "function1/0 docs."
416416

417417
assert Erlang.autolink_spec(hd(function1.specs), current_kfa: {:function, :function1, 0}) ==
418-
"function1() -> <a href=\"https://www.erlang.org/doc/man/erlang.html#type-atom\">atom</a>()."
418+
"function1() -> <a href=\"https://www.erlang.org/doc/man/erlang.html#t:atom/0\">atom</a>()."
419419

420420
%ExDoc.FunctionNode{
421421
id: "function2/0"
@@ -463,7 +463,7 @@ defmodule ExDoc.Retriever.ErlangTest do
463463
assert Path.basename(callback1.source_url) == "mod.erl:4"
464464

465465
assert Erlang.autolink_spec(hd(callback1.specs), current_kfa: {:callback, :callback1, 0}) ==
466-
"callback1() -> <a href=\"https://www.erlang.org/doc/man/erlang.html#type-atom\">atom</a>()."
466+
"callback1() -> <a href=\"https://www.erlang.org/doc/man/erlang.html#t:atom/0\">atom</a>()."
467467

468468
assert optional_callback1.id == "c:optional_callback1/0"
469469
assert optional_callback1.type == :callback
@@ -501,7 +501,7 @@ defmodule ExDoc.Retriever.ErlangTest do
501501
assert type1.doc |> DocAST.to_string() =~ "type1/0 docs."
502502

503503
assert type1.spec |> Erlang.autolink_spec(current_kfa: {:type, :type1, 0}) ==
504-
"type1() :: <a href=\"https://www.erlang.org/doc/man/erlang.html#type-atom\">atom</a>()."
504+
"type1() :: <a href=\"https://www.erlang.org/doc/man/erlang.html#t:atom/0\">atom</a>()."
505505
end
506506
end
507507
end

0 commit comments

Comments
 (0)