RobertDober / earmark_parser

The Markdown to AST part of Earmark.
Apache License 2.0
68 stars 26 forks source link

"Failed to find closing <p>" when newline and text is present, and newline not in the final result with `breaks: true` #158

Open spctrlth opened 3 months ago

spctrlth commented 3 months ago

For example, the following is correct:

iex(1)> EarmarkParser.as_ast("z\nz", %EarmarkParser.Options{breaks: true})
{:ok, [{"p", [], ["z", {"br", [], [], %{}}, "z"], %{}}], []}

It puts everything in a paragraph and the newline is turned into a br tag (as expected because of the breaks: true option)

However, when we put tags ourselves, in this case p tags, but also happens with other HTML tags

iex(1)> EarmarkParser.as_ast("<p>z\nz</p>", %EarmarkParser.Options{breaks: true})
{:error, [{"p", [], ["z", "z</p>"], %{verbatim: true}}],
 [{:warning, 1, "Failed to find closing <p>"}]}

The newline \n is not converted to a br tag (may be related to https://github.com/RobertDober/earmark_parser/issues/119 ?), and the closing tag is seen as part of the text instead of being detected as the closing tag.

spctrlth commented 3 months ago

backlink to downstream issue: https://akkoma.dev/AkkomaGang/akkoma/issues/829

RobertDober commented 3 months ago

I believe this is documented behavior, tags need to be in their own line (more or less) therefore

iex(2)> EarmarkParser.as_ast("<p>z\nz</p>")
{:error, [{"p", [], ["z", "z</p>"], %{verbatim: true}}],
 [{:warning, 1, "Failed to find closing <p>"}]}
iex(3)> EarmarkParser.as_ast("<p>z\nz\n</p>")
{:ok, [{"p", [], ["z", "z"], %{verbatim: true}}], []}

That said we want the behavior you are expecting, I'll keep this open as a Feature Request

RobertDober commented 3 months ago

related are #7

119

102