Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use EDoc link for erlang type #1065

Closed
wants to merge 1 commit into from
Closed
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
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
chulkilee marked this conversation as resolved.
Show resolved Hide resolved
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