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

Html in markdown generates 4 element tuple #1165

Closed
maartenvanvliet opened this issue May 15, 2020 · 1 comment · Fixed by #1166
Closed

Html in markdown generates 4 element tuple #1165

maartenvanvliet opened this issue May 15, 2020 · 1 comment · Fixed by #1166

Comments

@maartenvanvliet
Copy link
Contributor

In building the documentation for a package I came across an error in ExDoc when there was html in the markdown. This was the simplest test-case I found:

ExDoc.Markdown.to_ast("<p>\nTest\n</p>", []), calls into Earmark and it returns a 4 element tuple with %{meta: %{verbatim: true}} in the fourth element.

This is not being matched by ExDoc.Markdown.Earmark.fixup/1, see error below. Easy fix is to match it there and pass through the 4-element tuple but this leads to failures in other places the ast is walked over, e.g.

defp walk({tag, attrs, ast}, config) do

Other option is to ignore the fourth element and let fix_up/1 return a three element tuple but don't know the implications of that. Esp given this discussion in pragdave/earmark#337

  1) test to_ast/1 generate AST (ExDoc.Markdown.EarmarkTest)
     test/ex_doc/markdown/earmark_test.exs:9
     ** (FunctionClauseError) no function clause matching in ExDoc.Markdown.Earmark.fixup/1

     The following arguments were given to ExDoc.Markdown.Earmark.fixup/1:
     
         # 1
         {"p", [], ["Test"], %{meta: %{verbatim: true}}}
     
     Attempted function clauses (showing 3 out of 3):
     
         defp fixup(list) when is_list(list)
         defp fixup(binary) when is_binary(binary)
         defp fixup({tag, attrs, ast})
     
     code: assert Markdown.to_ast("<p>\nTest\n</p>", []) == [{:p, '', ["Test"]}]
     stacktrace:
       (ex_doc 0.22.0) lib/ex_doc/markdown/earmark.ex:58: ExDoc.Markdown.Earmark.fixup/1
       (elixir 1.10.1) lib/enum.ex:1396: Enum."-map/2-lists^map/1-0-"/2
       test/ex_doc/markdown/earmark_test.exs:12: (test)
@wojtekmach
Copy link
Member

Good catch, thank you for the report. I think it's ok to ignore the 4th element in the tuple for now and revisit it later when we'd use Earmark to transform ast back to html (then the extra info in the 4th element might be useful). Could you send a PR that ignores the 4th element?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants