Skip to content

Commit e7cb79c

Browse files
committed
Don't crash on markdown that triggers warning, fixes #1222
1 parent c864b91 commit e7cb79c

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

lib/ex_doc/markdown/earmark.ex

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ defmodule ExDoc.Markdown.Earmark do
4444

4545
{:error, ast, messages} ->
4646
print_messages(messages, options)
47-
ast
47+
fixup(ast)
4848
end
4949
end
5050

5151
defp print_messages(messages, options) do
5252
for {severity, line, message} <- messages do
53-
file = options.file
53+
file = options[:file]
5454
IO.warn("#{inspect(__MODULE__)} (#{severity}) #{file}:#{line} #{message}", [])
5555
end
5656
end
@@ -71,8 +71,7 @@ defmodule ExDoc.Markdown.Earmark do
7171
fixup({tag, attrs, ast})
7272
end
7373

74-
# E.g. `{:comment, _}`
75-
defp fixup(_) do
74+
defp fixup({:comment, _, _, _}) do
7675
[]
7776
end
7877

test/ex_doc/autolink_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,16 @@ defmodule ExDoc.AutolinkTest do
218218

219219
test "special case links" do
220220
assert autolink(~m"`//2`") ==
221-
{:a, [href: "https://hexdocs.pm/elixir/Kernel.html#//2"], [ast("//2")]}
221+
{:a, [href: "https://hexdocs.pm/elixir/Kernel.html#//2"], [ast("//2")]}
222222

223223
assert autolink(~m"[division](`//2`)") ==
224-
{:a, [href: "https://hexdocs.pm/elixir/Kernel.html#//2"], ["division"]}
224+
{:a, [href: "https://hexdocs.pm/elixir/Kernel.html#//2"], ["division"]}
225225

226226
assert autolink(~m"`Kernel.//2`") ==
227-
{:a, [href: "https://hexdocs.pm/elixir/Kernel.html#//2"], [ast("Kernel.//2")]}
227+
{:a, [href: "https://hexdocs.pm/elixir/Kernel.html#//2"], [ast("Kernel.//2")]}
228228

229229
assert autolink(~m"[division](`Kernel.//2`)") ==
230-
{:a, [href: "https://hexdocs.pm/elixir/Kernel.html#//2"], ["division"]}
230+
{:a, [href: "https://hexdocs.pm/elixir/Kernel.html#//2"], ["division"]}
231231
end
232232

233233
test "other link" do

test/ex_doc/markdown/earmark_test.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,12 @@ defmodule ExDoc.Markdown.EarmarkTest do
1919
test "comments" do
2020
assert Markdown.to_ast("<!-- INCLUDE -->", []) == []
2121
end
22+
23+
test "bug #1222" do
24+
assert ExUnit.CaptureIO.capture_io(:stderr, fn ->
25+
assert [{:p, [], _}] =
26+
Markdown.to_ast("{:ok, status, %MyApp.User{}} on success", [])
27+
end) =~ "ExDoc.Markdown.Earmark (warning)"
28+
end
2229
end
2330
end

0 commit comments

Comments
 (0)