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

#to_text should preserve whitespace between inline elements #71

Closed
timherby opened this issue May 6, 2014 · 4 comments
Closed

#to_text should preserve whitespace between inline elements #71

timherby opened this issue May 6, 2014 · 4 comments

Comments

@timherby
Copy link

timherby commented May 6, 2014

@flavorjones I love the that #to_text preserves whitespace (as you added here #12), but it doesn't appear to preserve between inline elements as you say in this post (sparklemotion/nokogiri#636), only block elements. Would it be reasonable for it to preserve whitespace between inline elements? Am I missing an option to do this? If not, would you be open to a pull request to make this happen?

@timherby
Copy link
Author

timherby commented May 6, 2014

An example of what I was hoping for:

html_text = "example:<a href=\"http://url.com/index.html\">http://url.com/index.html</a><a href=\"http://url.com/index2.html\">http://url.com/index2.html</a>"
Loofah.fragment(html_text).to_text

Expected:
"example: http://url.com/index.html http://url.com/index2.html"

Actual:
"example:http://url.com/index.htmlhttp://url.com/index2.html"

Similarly,
tags are not being seen as block tags:

html_text = "example:<br><a href=\"http://url.com/index.html\">http://url.com/index.html</a><br><a href=\"http://url.com/index2.html\">http://url.com/index2.html</a>"
Loofah.fragment(html_text).to_text

Expected:
"example:\nhttp://url.com/index.html\nhttp://url.com/index2.html"

Actual:
"example:http://url.com/index.htmlhttp://url.com/index2.html"

@chengguangnan
Copy link

I'd love to have this too.

@chengguangnan
Copy link

I set the gem's version to github and found that it's supported! Also, note that you need to call the method to_text rather than text, I thought they were the same.

@flavorjones flavorjones removed the OSL label Jun 6, 2015
@flavorjones
Copy link
Owner

I'm open to a PR of some sort that generates output as you describe. Let me know if you'd like direction or advice?

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

3 participants