mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 00:55:11 -07:00
Single regexp for strip_html
This commit is contained in:
@@ -11,6 +11,12 @@ module Liquid
|
|||||||
"'".freeze => '''.freeze
|
"'".freeze => '''.freeze
|
||||||
}
|
}
|
||||||
HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
|
HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
|
||||||
|
STRIP_HTML = Regexp.union(
|
||||||
|
/<script.*?<\/script>/m,
|
||||||
|
/<!--.*?-->/m,
|
||||||
|
/<style.*?<\/style>/m,
|
||||||
|
/<.*?>/m,
|
||||||
|
)
|
||||||
|
|
||||||
# Return the size of an array or of an string
|
# Return the size of an array or of an string
|
||||||
def size(input)
|
def size(input)
|
||||||
@@ -102,8 +108,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def strip_html(input)
|
def strip_html(input)
|
||||||
empty = ''.freeze
|
input.to_s.gsub(STRIP_HTML, ''.freeze)
|
||||||
input.to_s.gsub(/<script.*?<\/script>/m, empty).gsub(/<!--.*?-->/m, empty).gsub(/<style.*?<\/style>/m, empty).gsub(/<.*?>/m, empty)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove all newlines from the string
|
# Remove all newlines from the string
|
||||||
|
|||||||
Reference in New Issue
Block a user