Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/ex_doc/formatter/html/autolink.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ defmodule ExDoc.Formatter.HTML.Autolink do
timeout: 0
]

kernel_exports = Kernel.__info__(:functions) ++ Kernel.__info__(:macros)
special_form_exports = Kernel.SpecialForms.__info__(:macros)

@basic_type_strings (for {f, a} <- @basic_types, do: "t:#{f}/#{a}")
@built_in_type_strings (for {f, a} <- @built_in_types, do: "t:#{f}/#{a}")
@special_form_strings (for {f, a} <- Kernel.SpecialForms.__info__(:macros), do: "#{f}/#{a}")
@kernel_function_strings (for {f, a} <- kernel_exports, do: "#{f}/#{a}")
@special_form_strings (for {f, a} <- special_form_exports, do: "#{f}/#{a}")

@doc """
Receives a list of module nodes and autolink all docs and typespecs.
Expand Down Expand Up @@ -361,6 +365,9 @@ defmodule ExDoc.Formatter.HTML.Autolink do
match in @built_in_type_strings ->
"[`#{function}/#{arity}`](#{elixir_doc}#{@built_in_types_page})"

match in @kernel_function_strings ->
"[`#{function}/#{arity}`](#{elixir_doc}Kernel#{extension}##{prefix}#{enc_h function}/#{arity})"

match in @special_form_strings ->
"[`#{function}/#{arity}`](#{elixir_doc}Kernel.SpecialForms#{extension}##{prefix}#{enc_h function}/#{arity})"

Expand Down
16 changes: 8 additions & 8 deletions test/ex_doc/formatter/html/autolink_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ defmodule ExDoc.Formatter.HTML.AutolinkTest do
end

test "autolink creates links for special forms" do
assert Autolink.local_doc("`++/2`", ["++/2"]) === "[`++/2`](#++/2)"
assert Autolink.local_doc("`!/1`", ["!/1"]) === "[`!/1`](#!/1)"
assert Autolink.local_doc("`../2`", ["../2"]) === "[`../2`](#../2)"
assert Autolink.local_doc("`--/2`", ["--/2"]) === "[`--/2`](#--/2)"
assert Autolink.local_doc("`<<>>/1`", ["<<>>/1"]) === "[`<<>>/1`](#%3C%3C%3E%3E/1)"
assert Autolink.local_doc("`{}/1`", ["{}/1"]) === "[`{}/1`](#%7B%7D/1)"
end

test "autolink creates links for Kernel special forms" do
assert Autolink.local_doc("`<<>>/1`", ["<<>>/1"]) === "[`<<>>/1`](#%3C%3C%3E%3E/1)"
assert Autolink.local_doc("`<<>>/1`", []) ===
"[`<<>>/1`](#{@elixir_docs}elixir/Kernel.SpecialForms.html#%3C%3C%3E%3E/1)"
end

test "autolink creates links for Kernel functions" do
assert Autolink.local_doc("`abs/1`", ["abs/1"]) === "[`abs/1`](#abs/1)"
assert Autolink.local_doc("`abs/1`", []) === "[`abs/1`](#{@elixir_docs}elixir/Kernel.html#abs/1)"
assert Autolink.local_doc("`!/1`", ["!/1"]) === "[`!/1`](#!/1)"
assert Autolink.local_doc("`!/1`", []) === "[`!/1`](#{@elixir_docs}elixir/Kernel.html#!/1)"
end

# elixir_functions

test "autolink functions Module.fun/arity in docs" do
Expand Down