Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Parsing links with line breaks in the text cannot work steadily #796

Open
garygao opened this issue Jan 14, 2025 · 0 comments
Open

Parsing links with line breaks in the text cannot work steadily #796

garygao opened this issue Jan 14, 2025 · 0 comments

Comments

@garygao
Copy link

garygao commented Jan 14, 2025

render = ::Redcarpet::Render::HTML.new(hard_wrap: false)
extensions = {
  no_intra_emphasis: true,
  tables: true,
  autolink: true,
  strikethrough: true,
  disable_indented_code_blocks: true,
  superscript: true,
}
parser = ::Redcarpet::Markdown.new(render, extensions)

Example 1, the URL can be parsed as a <a> tag, it works.

subject.render("<html>\n\n<div>www.test.com</div></html>")
# => "<p><html></p>\n\n<p><div><a href=\"http://www.test.com\">www.test.com</a></div></html></p>\n"

Example 2, the first URL cannot be parsed as a <a> tag, only the second URL works.

subject.render("<html>\n\n<div>www.test.com</div>\n\n<div>www.test.com</div></html>")
# => "<p><html></p>\n\n<div>www.test.com</div>\n\n<p><div><a href=\"http://www.test.com\">www.test.com</a></div></html></p>\n"

Example 3, both URLs can be parsed correctly, the difference is there is only one line break in front of the first <div>.

subject.render("<html>\n<div>www.test.com</div>\n\n<div>www.test.com</div></html>")
# => "<p><html>\n<div><a href=\"http://www.test.com\">www.test.com</a></div></p>\n\n<p><div><a href=\"http://www.test.com\">www.test.com</a></div></html></p>\n"
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant