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

List lines with a comment before a markdown link are not properly rendered #902

Closed
Iiridayn opened this issue Jan 31, 2025 · 4 comments
Closed

Comments

@Iiridayn
Copy link

MRE:

$parsedown = new Parsedown();
echo $parsedown->text("- <!-- test -->[foo](bar)");

Expected:

<ul>
<li><!-- test --><a href="bar">foo</a></li>
</ul>

Got:

<ul>
<li>
<!-- test -->[foo](bar)
</li>
</ul>
@taufik-nurrohman
Copy link

taufik-nurrohman commented Jan 31, 2025

It is what it should be, based on the CommonMark specification. Because it is treated as HTML block type 2:

https://spec.commonmark.org/0.31.2#example-177

@Iiridayn
Copy link
Author

You have linked me a specification which this converter conforms to. Although I feel the decisions made by the specification violate the principle of least astonishment, it is probably not worth the effort to pursue this further. Thank you for your clear and concise answer.

Would you happen to know if I can cleanly get the output desired? My new understanding is that newlines end both the "HTML block type 2" and the list item, and I have just finished converting all of my user-generated HTML to markdown as a more user-friendly (and easier to secure) alternative, with a few small issues like this one. (For example, I had to subclass Parsedown to support HTML comments in safe mode since I understand Markdown doesn't support comments, and the existing user HTML includes a number of valuable comments).

@Iiridayn Iiridayn closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2025
@taufik-nurrohman
Copy link

Try escaping (untested):

- \<!-- test --\>[foo](bar)

@Iiridayn
Copy link
Author

Iiridayn commented Jan 31, 2025

Thank you - - \<!-- test -->[foo](bar) almost works, gives me <li>\<!-- test --><a href="bar">foo</a></li>. Just needs to strip the escape character now, but I already opened #903 about a related issue w/escape characters.

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

No branches or pull requests

2 participants