Skip to content

Html in markdown generates 4 element tuple #1165

Closed
@maartenvanvliet

Description

@maartenvanvliet

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions