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

"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 this issue Aug 18, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@spctrlth
Copy link

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 #119 ?), and the closing tag is seen as part of the text instead of being detected as the closing tag.

@spctrlth
Copy link
Author

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

@spctrlth spctrlth changed the title "Failed to find closing <p>" when newline and text is present, leading to newline not being in the final result with breaks: true "Failed to find closing <p>" when newline and text is present, and newline not in the final result with breaks: true Aug 18, 2024
@RobertDober
Copy link
Owner

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 RobertDober added the enhancement New feature or request label Aug 19, 2024
@RobertDober
Copy link
Owner

RobertDober commented Aug 19, 2024

related are #7
#119
#102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants