Skip to content

Commit

Permalink
Use EDoc link for erlang type
Browse files Browse the repository at this point in the history
  • Loading branch information
chulkilee committed Jul 24, 2019
1 parent ab8a16c commit ed21fe6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/ex_doc/formatter/html/autolink.ex
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,17 @@ defmodule ExDoc.Formatter.HTML.Autolink do

defp type_remote_url(source, alias, name, args) do
name = enc("#{name}")
"#{source}#{enc(inspect(alias))}.html#t:#{name}/#{length(args)}"

if erlang_alias?(alias) do
"#{source}#{enc(to_string(alias))}.html#type-#{name}"
else
"#{source}#{enc(inspect(alias))}.html#t:#{name}/#{length(args)}"
end
end

defp erlang_alias?(alias) do
first_char = alias |> to_string() |> String.at(0)
first_char == String.downcase(first_char)
end

defp typespec_string_to_link(string, url) do
Expand Down
7 changes: 6 additions & 1 deletion test/ex_doc/formatter/html/autolink_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,16 @@ defmodule ExDoc.Formatter.HTML.AutolinkTest do
~s[<a href=\"#{@erlang_docs}sets.html#type-set\">:sets.set</a>(<a href=\"#t:foo/0\">foo</a>())]
end

test "autolinks shared aliases" do
test "autolinks shared Elixir aliases for ex_doc" do
assert Autolink.typespec(quote(do: Foo.t()), [], [Foo]) ==
~s[<a href="Foo.html#t:t/0">Foo.t</a>()]
end

test "autolinks shared Erlang aliases for EDoc" do
assert Autolink.typespec(quote(do: :foo.t()), [], [:foo]) ==
~s[<a href="foo.html#type-t">:foo.t</a>()]
end

test "autolinks inside parameterized types" do
assert Autolink.typespec(quote(do: t(foo())), [t: 1, foo: 0], []) ==
~s[<a href="#t:t/1">t</a>(<a href="#t:foo/0">foo</a>())]
Expand Down

0 comments on commit ed21fe6

Please sign in to comment.