diff --git a/lib/ex_doc/autolink.ex b/lib/ex_doc/autolink.ex index b26d55df5..f7beb46fe 100644 --- a/lib/ex_doc/autolink.ex +++ b/lib/ex_doc/autolink.ex @@ -335,8 +335,8 @@ defmodule ExDoc.Autolink do end defp parse_url(string, mode, config) do - case Regex.run(~r{^(.+)/(\d+)$}, string) do - [_, left, right] -> + case Regex.run(~r{^(.+)/(\d+)(#.*)?$}, string) do + [_, left, right | maybe_fragment] -> with {:ok, arity} <- parse_arity(right) do {kind, rest} = kind(left) @@ -344,11 +344,13 @@ defmodule ExDoc.Autolink do {:local, function} -> kind |> local_url(function, arity, config, string, mode: mode) + |> maybe_append_nested_fragment(maybe_fragment) |> maybe_remove_link(mode) {:remote, module, function} -> {kind, module, function, arity} |> remote_url(config, string, mode: mode) + |> maybe_append_nested_fragment(maybe_fragment) |> maybe_remove_link(mode) :error -> @@ -611,6 +613,10 @@ defmodule ExDoc.Autolink do def format_visibility(:undefined, _kind), do: "undefined or private" def format_visibility(visibility, _kind), do: "#{visibility}" + defp maybe_append_nested_fragment(nil, _), do: nil + defp maybe_append_nested_fragment(url, []), do: url + defp maybe_append_nested_fragment(url, ["#" <> fragment]), do: url <> "-" <> fragment + defp append_fragment(url, nil), do: url defp append_fragment(url, fragment), do: url <> "#" <> fragment end diff --git a/test/ex_doc/language/elixir_test.exs b/test/ex_doc/language/elixir_test.exs index 69b4b8eb4..8af557826 100644 --- a/test/ex_doc/language/elixir_test.exs +++ b/test/ex_doc/language/elixir_test.exs @@ -148,6 +148,11 @@ defmodule ExDoc.Language.ElixirTest do ~s|GenServer.handle_call/3| end + test "elixir callback fragment" do + assert autolink_doc("`c:GenServer.handle_call/3#fragment`") == + ~s|GenServer.handle_call/3| + end + test "erlang callback" do assert autolink_doc("`c::gen_server.handle_call/3`") == ~s|:gen_server.handle_call/3|