Skip to content

Commit 77c3321

Browse files
committed
Fix autolink anchors for non URL safe function names
1 parent 6334219 commit 77c3321

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

lib/ex_doc/formatter/html/autolink.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,10 @@ defmodule ExDoc.Formatter.HTML.Autolink do
208208
|> List.flatten()
209209
|> Enum.filter(&(&1 in locals))
210210
|> Enum.reduce(bin, fn (x, acc) ->
211+
{prefix, _, function_name, arity} = split_function(x)
211212
escaped = Regex.escape(x)
212-
Regex.replace(~r/(?<!\[)`(\s*(#{escaped})\s*)`(?!\])/, acc, "[`\\1`](#\\2)")
213+
Regex.replace(~r/(?<!\[)`(\s*#{escaped}\s*)`(?!\])/, acc,
214+
"[`#{function_name}/#{arity}`](##{prefix}#{enc_h function_name}/#{arity})")
213215
end)
214216
end
215217

@@ -250,7 +252,7 @@ defmodule ExDoc.Formatter.HTML.Autolink do
250252
{prefix, mod_str, function_name, arity} = split_function(x)
251253
escaped = Regex.escape(x)
252254
Regex.replace(~r/(?<!\[)`(\s*#{escaped}\s*)`(?!\])/, acc,
253-
"[`#{mod_str}.#{function_name}/#{arity}`](#{mod_str}.html##{prefix}#{function_name}/#{arity})")
255+
"[`#{mod_str}.#{function_name}/#{arity}`](#{mod_str}.html##{prefix}#{enc_h function_name}/#{arity})")
254256
end)
255257
end
256258

@@ -319,7 +321,7 @@ defmodule ExDoc.Formatter.HTML.Autolink do
319321
{_, mod_str, function_name, arity} = split_function(x)
320322
escaped = Regex.escape(x)
321323
Regex.replace(~r/(?<!\[)`(\s*:#{escaped}\s*)`(?!\])/, acc,
322-
"[`\\1`](#{@erlang_docs}#{mod_str}.html##{function_name}-#{arity})")
324+
"[`\\1`](#{@erlang_docs}#{mod_str}.html##{enc_h function_name}-#{arity})")
323325
end)
324326
end
325327

mix.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"excoveralls": {:hex, :excoveralls, "0.3.11"},
33
"exjsx": {:hex, :exjsx, "3.2.0"},
44
"hackney": {:hex, :hackney, "1.3.2"},
5-
"hoedown": {:git, "git://github.com/hoedown/hoedown.git", "2a4cf17c70e6572ed42cdca3ea7ca3e768ed17be", []},
5+
"hoedown": {:git, "https://github.com/hoedown/hoedown.git", "2a4cf17c70e6572ed42cdca3ea7ca3e768ed17be", []},
66
"idna": {:hex, :idna, "1.0.2"},
77
"jsx": {:hex, :jsx, "2.6.2"},
8-
"markdown": {:git, "git://github.com/devinus/markdown.git", "cd0df79b6f1cc374499d47f6ba6aaab5096f874f", []},
8+
"markdown": {:git, "https://github.com/devinus/markdown.git", "cd0df79b6f1cc374499d47f6ba6aaab5096f874f", []},
99
"ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.5"}}

test/ex_doc/formatter/html/autolink_test.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defmodule ExDoc.Formatter.HTML.AutolinkTest do
1010
assert Autolink.local_doc("`example/2` then `example/2`",
1111
["example/2"]) == "[`example/2`](#example/2) then [`example/2`](#example/2)"
1212
assert Autolink.local_doc("` spaces/0 `", ["spaces/0"]) ==
13-
"[` spaces/0 `](#spaces/0)"
13+
"[`spaces/0`](#spaces/0)"
1414
assert Autolink.local_doc("`example/1` and `example/2`",
1515
["example/1", "example/2"]) == "[`example/1`](#example/1) and [`example/2`](#example/2)"
1616
assert Autolink.local_doc("`funny_name\?/1` and `funny_name!/2`",
@@ -33,6 +33,7 @@ defmodule ExDoc.Formatter.HTML.AutolinkTest do
3333
assert Autolink.local_doc("`!/1`", ["!/1"]) === "[`!/1`](#!/1)"
3434
assert Autolink.local_doc("`../2`", ["../2"]) === "[`../2`](#../2)"
3535
assert Autolink.local_doc("`--/2`", ["--/2"]) === "[`--/2`](#--/2)"
36+
assert Autolink.local_doc("`<<>>/1`", ["<<>>/1"]) === "[`<<>>/1`](#%3C%3C%3E%3E/1)"
3637
end
3738

3839
# project_functions

0 commit comments

Comments
 (0)