mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
22 lines
548 B
Ruby
22 lines
548 B
Ruby
module HtmlHelper
|
|
def strip_html(html)
|
|
strip_surrounding_whitespace substitute_entities strip_tags add_linebreaks html
|
|
end
|
|
|
|
def substitute_entities(html)
|
|
html.andand.gsub(/ /i, ' ').andand.gsub(/&/i, '&')
|
|
end
|
|
|
|
def add_linebreaks(html)
|
|
# I know Cthulu is coming for me. Forgive me.
|
|
# http://stackoverflow.com/a/1732454/2720566
|
|
html.
|
|
andand.gsub(/<\/h[^>]>|<\/p>|<\/div>/, "\\1\n\n").
|
|
andand.gsub(/<br[^>]*>/, "\\1\n")
|
|
end
|
|
|
|
def strip_surrounding_whitespace(html)
|
|
html.andand.strip
|
|
end
|
|
end
|