Skip to content

Commit

Permalink
feature: use nokogiri for strip tags
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarinEA committed Sep 23, 2019
1 parent 2054e2a commit f495195
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/string_tools/core_ext/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require 'active_support/version'
require 'action_pack'
require 'string_tools/string'
require 'action_controller'

class String
%w[auto_link excerpt highlight sanitize simple_format word_wrap].each do |method|
Expand All @@ -19,7 +18,7 @@ def #{method}(*args)
# возвращает строку из которой удалены HTML-теги
# символы <>&" остаются без изменения
def strip_tags
ActionController::Base.helpers.strip_tags(self).to_str.gsub(/<!--/, '<--')
Nokogiri::HTML5.parse(self).content
end

# '11,3'.to_f
Expand Down
4 changes: 2 additions & 2 deletions spec/string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
'some<!-- comment -->text' => 'sometext',
'some<ul>text' => 'sometext',
'some<script>text</script>' => 'sometext',
'some<!-- comment' => 'some<-- comment',
'some<!-- comment' => 'some',
'<h1 style="coller:red">>text</h1>>' => '>text>',
" <ul>list<li>text</li>\n <li>text2</li> " => " listtext\n text2 "
" <ul>list<li>text</li>\n <li>text2</li> " => "listtext\n text2 "
}.each do |example_string, result|
context "when string '#{example_string}'" do
it { expect(example_string.dup.strip_tags).to eq result }
Expand Down

0 comments on commit f495195

Please sign in to comment.