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
13 changes: 9 additions & 4 deletions lib/ex_doc/formatter/html/autolink.ex
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ defmodule ExDoc.Formatter.HTML.Autolink do
will get translated to the new href of the function.
"""
def local_doc(bin, locals, aliases \\ [], extension \\ ".html", lib_dirs \\ elixir_lib_dirs()) when is_binary(bin) do
fun_re = Regex.source(~r{(([ct]:)?([a-z_]+[A-Za-z_\d]*[\\?\\!]?|[\{\}=&\\|\\.<>~*^@\\+\\%\\!-]+)/\d+)})
fun_re = Regex.source(~r{(([ct]:)?([a-z_]+[A-Za-z_\d]*[\\?\\!]?|[\{\}=&\\|\\.<>~*^@\\+\\%\\!-\/]+)/\d+)})
regex = ~r{(?<!\[)`\s*(#{fun_re})\s*`(?!\])}
elixir_docs = get_elixir_docs(aliases, lib_dirs)

Expand Down Expand Up @@ -419,7 +419,7 @@ defmodule ExDoc.Formatter.HTML.Autolink do
end

module_re = Regex.source(~r{(([A-Z][A-Za-z_\d]+)\.)+})
fun_re = Regex.source(~r{([ct]:)?(#{module_re}([a-z_]+[A-Za-z_\d]*[\\?\\!]?|[\{\}=&\\|\\.<>~*^@\\+\\%\\!-]+)/\d+)})
fun_re = Regex.source(~r{([ct]:)?(#{module_re}(([a-z_]+[A-Za-z_\d]*[\\?\\!]?)|[\{\}=&\\|\\.<>~*^@\\+\\%\\!-\/]+)/\d+)})
@custom_re ~r{\[(.*?)\]\(`(#{fun_re})`\)}
@normal_re ~r{(?<!\[)`\s*(#{fun_re})\s*`(?!\])}

Expand Down Expand Up @@ -489,15 +489,20 @@ defmodule ExDoc.Formatter.HTML.Autolink do
{_, mod, fun, arity} = split_function(bin)
{"t:", mod, fun, arity}
end
defp split_function(bin) do
[modules, arity] = String.split(bin, "/")
defp split_function(bin) when is_binary(bin) do
split_function(String.split(bin, "/"))
end
defp split_function([modules, arity]) do
{mod, name} =
modules
|> String.replace(~r{([^\.])\.}, "\\1 ") # this handles the case of the ".." function
|> String.split(" ")
|> Enum.split(-1)
{"", Enum.join(mod, "."), hd(name), arity}
end
defp split_function([modules, "", arity]) do # handles "/" function
split_function([modules <> "/", arity])
end

@doc """
Create links to Erlang functions in code blocks.
Expand Down
4 changes: 4 additions & 0 deletions test/ex_doc/formatter/html/autolink_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ defmodule ExDoc.Formatter.HTML.AutolinkTest do
assert Autolink.local_doc("`funny_name\?/1` and `funny_name!/2`",
["funny_name\?/1", "funny_name!/2"]) ==
"[`funny_name\?/1`](#funny_name\?/1) and [`funny_name!/2`](#funny_name!/2)"
assert Autolink.local_doc("`//2`", ["//2"]) == "[`//2`](#//2)"
end

test "autolink to local callbacks" do
Expand Down Expand Up @@ -143,6 +144,9 @@ defmodule ExDoc.Formatter.HTML.AutolinkTest do

assert Autolink.elixir_functions("[`f`](`Foo.foo/1`), [`f`](`Foo.foo/1`)", ["Foo.foo/1"]) ==
"[`f`](Foo.html#foo/1), [`f`](Foo.html#foo/1)"

assert Autolink.elixir_functions("[`foo`](`Foo.//2`)", ["Foo.//2"]) ==
"[`foo`](Foo.html#//2)"
end

test "autolink functions to types in the project" do
Expand Down