Skip to content

Commit d1b0950

Browse files
authored
Replace OTP /man/ links with /apps/:app/ (#1909)
1 parent 2f23a05 commit d1b0950

File tree

5 files changed

+72
-78
lines changed

5 files changed

+72
-78
lines changed

lib/ex_doc/autolink.ex

+14-20
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,21 @@ defmodule ExDoc.Autolink do
6363
]
6464

6565
@hexdocs "https://hexdocs.pm/"
66-
@otpdocs "https://www.erlang.org/doc/man/"
6766
@otpappdocs "https://www.erlang.org/doc/apps/"
6867

69-
def app_module_url(tool, module, anchor \\ nil, config)
68+
def app_module_url(tool, module, anchor \\ "#content", config)
7069

71-
def app_module_url(:ex_doc, module, nil, %{current_module: module} = config) do
72-
app_module_url(:ex_doc, module, "#content", config)
73-
end
70+
def app_module_url(:no_tool, _, _, _), do: nil
7471

75-
def app_module_url(:ex_doc, module, anchor, %{current_module: module} = config) do
76-
path = module |> inspect() |> String.trim_leading(":")
77-
ex_doc_app_url(module, config, path, config.ext, "#{anchor}")
78-
end
72+
def app_module_url(tool, module, anchor, config) do
73+
base_url =
74+
case tool do
75+
:ex_doc -> @hexdocs
76+
:otp -> @otpappdocs
77+
end
7978

80-
def app_module_url(:ex_doc, module, anchor, config) do
8179
path = module |> inspect() |> String.trim_leading(":")
82-
ex_doc_app_url(module, config, path, config.ext, "#{anchor}")
83-
end
84-
85-
def app_module_url(:otp, module, anchor, _config) do
86-
@otpdocs <> "#{module}.html#{anchor}"
87-
end
88-
89-
def app_module_url(:no_tool, _, _, _) do
90-
nil
80+
app_url(base_url, module, config, path, config.ext, "#{anchor}")
9181
end
9282

9383
defp string_app_module_url(string, tool, module, anchor, config) do
@@ -109,12 +99,16 @@ defmodule ExDoc.Autolink do
10999

110100
@doc false
111101
def ex_doc_app_url(module, config, path, ext, suffix) do
102+
app_url(@hexdocs, module, config, path, ext, suffix)
103+
end
104+
105+
defp app_url(base_url, module, config, path, ext, suffix) do
112106
if app = app(module) do
113107
if app in config.apps do
114108
path <> ext <> suffix
115109
else
116110
config.deps
117-
|> Keyword.get_lazy(app, fn -> @hexdocs <> "#{app}" end)
111+
|> Keyword.get_lazy(app, fn -> base_url <> "#{app}" end)
118112
|> String.trim_trailing("/")
119113
|> Kernel.<>("/" <> path <> ".html" <> suffix)
120114
end

test/ex_doc/formatter/html/erlang_test.exs

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ defmodule ExDoc.Formatter.HTML.ErlangTest do
3333
html = Floki.raw_html(doc)
3434

3535
assert html =~
36-
~s|-spec</span> foo(<a href=\"#t:t/0\">t</a>()) -&gt; <a href=\"#t:t/0\">t</a>().|
36+
~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#t:atom/0\">atom</a>().|
39+
~s|-type</span> t() :: <a href="https://www.erlang.org/doc/apps/erts/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#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}.|
42+
~s|-type</span> t2() :: #rec{k1 :: <a href="https://www.erlang.org/doc/apps/stdlib/uri_string.html#t:uri_string/0">uri_string:uri_string</a>(), k2 :: <a href="https://www.erlang.org/doc/apps/stdlib/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

+8-8
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ defmodule ExDoc.Language.ElixirTest do
4040

4141
test "m:module with Erlang module" do
4242
assert autolink_doc("`m::array`") ==
43-
~s|<a href="https://www.erlang.org/doc/man/array.html"><code class="inline">:array</code></a>|
43+
~s|<a href="https://www.erlang.org/doc/apps/stdlib/array.html"><code class="inline">:array</code></a>|
4444
end
4545

4646
test "m:module with Erlang module and fragment" do
4747
assert autolink_doc("`m::array#fragment`") ==
48-
~s|<a href="https://www.erlang.org/doc/man/array.html#fragment"><code class="inline">:array</code></a>|
48+
~s|<a href="https://www.erlang.org/doc/apps/stdlib/array.html#fragment"><code class="inline">:array</code></a>|
4949
end
5050

5151
test "module with fragment without m: does not link" do
@@ -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/apps/stdlib/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#c:handle_call/3"><code class="inline">:gen_server.handle_call/3</code></a>|
153+
~s|<a href="https://www.erlang.org/doc/apps/stdlib/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#t:array/0"><code class="inline">:array.array/0</code></a>|
174+
~s|<a href="https://www.erlang.org/doc/apps/stdlib/array.html#t:array/0"><code class="inline">:array.array/0</code></a>|
175175
end
176176

177177
test "special forms" do
@@ -204,10 +204,10 @@ defmodule ExDoc.Language.ElixirTest do
204204
~s|<a href="https://hexdocs.pm/elixir/String.html#at/2">custom text</a>|
205205

206206
assert autolink_doc("[custom text](`:lists`)") ==
207-
~s|<a href="https://www.erlang.org/doc/man/lists.html">custom text</a>|
207+
~s|<a href="https://www.erlang.org/doc/apps/stdlib/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/apps/stdlib/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#t:set/0">:sets.set</a>()]
453+
~s[t() :: <a href="https://www.erlang.org/doc/apps/stdlib/sets.html#t:set/0">:sets.set</a>()]
454454
end
455455

456456
test "escape special HTML characters" do

0 commit comments

Comments
 (0)