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

Escape html for description #129

Open
beagleknight opened this issue Mar 15, 2017 · 1 comment
Open

Escape html for description #129

beagleknight opened this issue Mar 15, 2017 · 1 comment

Comments

@beagleknight
Copy link

Hi there!

We are currently using this gem in our project https://github.com/AjuntamentdeBarcelona/decidim and we found a bug when having descriptions with single quotes in the description like s'explicarà.

I checked your gem and I see you are using html_escape for the title but not for the description. I just want to know if this is intended or not 😄

Thanks!

@jcuervo
Copy link

jcuervo commented Nov 28, 2018

Anybody who comes down this line trying to truncate description for whatever use and breaking the the layout for one way or another, the solution I implemented was via nokogiri:

def social_share_description(description)
  doc = Nokogiri::HTML::DocumentFragment.parse(description)
    
  doc.search('br').remove
  doc.to_html
end

This sample strips off all the br tags, irregardless if they are written in <br>, <br />, <br >. You might need to require 'nokogiri'.

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
@jcuervo @beagleknight and others