Skip to content

Commit

Permalink
Don't crash on markdown that triggers warning, fixes #1222
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmach committed Jul 20, 2020
1 parent c864b91 commit e7cb79c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 3 additions & 4 deletions lib/ex_doc/markdown/earmark.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ defmodule ExDoc.Markdown.Earmark do

{:error, ast, messages} ->
print_messages(messages, options)
ast
fixup(ast)
end
end

defp print_messages(messages, options) do
for {severity, line, message} <- messages do
file = options.file
file = options[:file]
IO.warn("#{inspect(__MODULE__)} (#{severity}) #{file}:#{line} #{message}", [])
end
end
Expand All @@ -71,8 +71,7 @@ defmodule ExDoc.Markdown.Earmark do
fixup({tag, attrs, ast})
end

# E.g. `{:comment, _}`
defp fixup(_) do
defp fixup({:comment, _, _, _}) do
[]
end

Expand Down
8 changes: 4 additions & 4 deletions test/ex_doc/autolink_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,16 @@ defmodule ExDoc.AutolinkTest do

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

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

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

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

test "other link" do
Expand Down
7 changes: 7 additions & 0 deletions test/ex_doc/markdown/earmark_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@ defmodule ExDoc.Markdown.EarmarkTest do
test "comments" do
assert Markdown.to_ast("<!-- INCLUDE -->", []) == []
end

test "bug #1222" do
assert ExUnit.CaptureIO.capture_io(:stderr, fn ->
assert [{:p, [], _}] =
Markdown.to_ast("{:ok, status, %MyApp.User{}} on success", [])
end) =~ "ExDoc.Markdown.Earmark (warning)"
end
end
end

0 comments on commit e7cb79c

Please sign in to comment.