Skip to content

Commit

Permalink
Merge pull request #57 from LostKobrakai/strip_html
Browse files Browse the repository at this point in the history
Implement strip_html filter
  • Loading branch information
edgurgel authored Jan 29, 2021
2 parents 79a849c + 2b182b1 commit ea18427
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/solid/filter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -672,4 +672,23 @@ defmodule Solid.Filter do
def where(input, key) do
for %{} = map <- input, Map.has_key?(map, key), do: map
end

@doc """
Removes any HTML tags from a string.
This mimics the regex based approach of the ruby library.
Output
iex> Solid.Filter.strip_html("Have <em>you</em> read <strong>Ulysses</strong>?")
"Have you read Ulysses?"
"""
@html_blocks ~r{(<script.*?</script>)|(<!--.*?-->)|(<style.*?</style>)}m
@html_tags ~r|<.*?>|m
@spec strip_html(iodata()) :: String.t()
def strip_html(iodata) do
iodata
|> IO.iodata_to_binary()
|> String.replace(@html_blocks, "")
|> String.replace(@html_tags, "")
end
end
1 change: 1 addition & 0 deletions test/cases/107/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions test/cases/107/input.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }}

0 comments on commit ea18427

Please sign in to comment.