Module: Loofah
- Defined in:
- lib/loofah.rb,
lib/loofah.rb,
lib/loofah/helpers.rb,
lib/loofah/version.rb,
lib/loofah/concerns.rb,
lib/loofah/elements.rb,
lib/loofah/scrubber.rb,
lib/loofah/scrubbers.rb,
lib/loofah/html5/scrub.rb,
lib/loofah/metahelpers.rb,
lib/loofah/xml/document.rb,
lib/loofah/html4/document.rb,
lib/loofah/html5/document.rb,
lib/loofah/html5/safelist.rb,
lib/loofah/xml/document_fragment.rb,
lib/loofah/html4/document_fragment.rb,
lib/loofah/html5/document_fragment.rb,
lib/loofah/html5/libxml2_workarounds.rb
Overview
Strings and IO Objects as Input
The following methods accept any IO object in addition to accepting a string:
-
Loofah.html4_document
-
Loofah.html4_fragment
-
Loofah.scrub_html4_document
-
Loofah.scrub_html4_fragment
-
Loofah.html5_document
-
Loofah.html5_fragment
-
Loofah.scrub_html5_document
-
Loofah.scrub_html5_fragment
-
Loofah.xml_document
-
Loofah.xml_fragment
-
Loofah.scrub_xml_document
-
Loofah.scrub_xml_fragment
-
Loofah.document
-
Loofah.fragment
-
Loofah.scrub_document
-
Loofah.scrub_fragment
That IO object could be a file, or a socket, or a StringIO, or anything that responds to read
and close
.
Defined Under Namespace
Modules: DocumentDecorator, Elements, HTML4, HTML5, Helpers, HtmlDocumentBehavior, HtmlFragmentBehavior, LibxmlWorkarounds, MetaHelpers, ScrubBehavior, Scrubbers, TextBehavior, XML Classes: Scrubber, ScrubberNotFound
Constant Summary collapse
- HTML =
Alias for Loofah::HTML4
HTML4
- VERSION =
The version of Loofah you are using
"2.23.1"
Class Method Summary collapse
-
.html4_document(*args, &block) ⇒ Object
(also: document)
Shortcut for Loofah::HTML4::Document.parse(*args, &block).
-
.html4_fragment(*args, &block) ⇒ Object
(also: fragment)
Shortcut for Loofah::HTML4::DocumentFragment.parse(*args, &block).
- .html5_support? ⇒ Boolean
-
.remove_extraneous_whitespace(string) ⇒ Object
A helper to remove extraneous whitespace from text-ified HTML.
-
.scrub_html4_document(string_or_io, method) ⇒ Object
(also: scrub_document)
Shortcut for Loofah::HTML4::Document.parse(string_or_io).scrub!(method).
-
.scrub_html4_fragment(string_or_io, method) ⇒ Object
(also: scrub_fragment)
Shortcut for Loofah::HTML4::DocumentFragment.parse(string_or_io).scrub!(method).
-
.scrub_xml_document(string_or_io, method) ⇒ Object
Shortcut for Loofah.xml_document(string_or_io).scrub!(method).
-
.scrub_xml_fragment(string_or_io, method) ⇒ Object
Shortcut for Loofah.xml_fragment(string_or_io).scrub!(method).
-
.xml_document(*args, &block) ⇒ Object
Shortcut for Loofah::XML::Document.parse(*args, &block).
-
.xml_fragment(*args, &block) ⇒ Object
Shortcut for Loofah::XML::DocumentFragment.parse(*args, &block).
Instance Method Summary collapse
-
#html5_document(*args, &block) ⇒ Object
Shortcut for Loofah::HTML5::Document.parse(*args, &block).
-
#html5_fragment(*args, &block) ⇒ Object
Shortcut for Loofah::HTML5::DocumentFragment.parse(*args, &block).
-
#scrub_html5_document(string_or_io, method) ⇒ Object
Shortcut for Loofah::HTML5::Document.parse(string_or_io).scrub!(method).
-
#scrub_html5_fragment(string_or_io, method) ⇒ Object
Shortcut for Loofah::HTML5::DocumentFragment.parse(string_or_io).scrub!(method).
Class Method Details
.html4_document(*args, &block) ⇒ Object Also known as: document
Shortcut for Loofah::HTML4::Document.parse(*args, &block)
This method accepts the same parameters as Nokogiri::HTML4::Document.parse
76 77 78 |
# File 'lib/loofah.rb', line 76 def html4_document(*args, &block) Loofah::HTML4::Document.parse(*args, &block) end |
.html4_fragment(*args, &block) ⇒ Object Also known as: fragment
Shortcut for Loofah::HTML4::DocumentFragment.parse(*args, &block)
This method accepts the same parameters as Nokogiri::HTML4::DocumentFragment.parse
83 84 85 |
# File 'lib/loofah.rb', line 83 def html4_fragment(*args, &block) Loofah::HTML4::DocumentFragment.parse(*args, &block) end |
.html5_support? ⇒ Boolean
7 8 9 10 11 12 13 14 15 |
# File 'lib/loofah.rb', line 7 def html5_support? # Note that Loofah can only support HTML5 in Nokogiri >= 1.14.0 because it requires the # subclassing fix from https://github.com/sparklemotion/nokogiri/pull/2534 return @html5_support if defined? @html5_support @html5_support = Gem::Version.new(Nokogiri::VERSION) > Gem::Version.new("1.14.0") && Nokogiri.uses_gumbo? end |
.remove_extraneous_whitespace(string) ⇒ Object
A helper to remove extraneous whitespace from text-ified HTML
169 170 171 |
# File 'lib/loofah.rb', line 169 def remove_extraneous_whitespace(string) string.gsub(/\n\s*\n\s*\n/, "\n\n") end |
.scrub_html4_document(string_or_io, method) ⇒ Object Also known as: scrub_document
Shortcut for Loofah::HTML4::Document.parse(string_or_io).scrub!(method)
88 89 90 |
# File 'lib/loofah.rb', line 88 def scrub_html4_document(string_or_io, method) Loofah::HTML4::Document.parse(string_or_io).scrub!(method) end |
.scrub_html4_fragment(string_or_io, method) ⇒ Object Also known as: scrub_fragment
Shortcut for Loofah::HTML4::DocumentFragment.parse(string_or_io).scrub!(method)
93 94 95 |
# File 'lib/loofah.rb', line 93 def scrub_html4_fragment(string_or_io, method) Loofah::HTML4::DocumentFragment.parse(string_or_io).scrub!(method) end |
.scrub_xml_document(string_or_io, method) ⇒ Object
Shortcut for Loofah.xml_document(string_or_io).scrub!(method)
164 165 166 |
# File 'lib/loofah.rb', line 164 def scrub_xml_document(string_or_io, method) Loofah.xml_document(string_or_io).scrub!(method) end |
.scrub_xml_fragment(string_or_io, method) ⇒ Object
Shortcut for Loofah.xml_fragment(string_or_io).scrub!(method)
159 160 161 |
# File 'lib/loofah.rb', line 159 def scrub_xml_fragment(string_or_io, method) Loofah.xml_fragment(string_or_io).scrub!(method) end |
.xml_document(*args, &block) ⇒ Object
Shortcut for Loofah::XML::Document.parse(*args, &block)
This method accepts the same parameters as Nokogiri::XML::Document.parse
147 148 149 |
# File 'lib/loofah.rb', line 147 def xml_document(*args, &block) Loofah::XML::Document.parse(*args, &block) end |
.xml_fragment(*args, &block) ⇒ Object
Shortcut for Loofah::XML::DocumentFragment.parse(*args, &block)
This method accepts the same parameters as Nokogiri::XML::DocumentFragment.parse
154 155 156 |
# File 'lib/loofah.rb', line 154 def xml_fragment(*args, &block) Loofah::XML::DocumentFragment.parse(*args, &block) end |
Instance Method Details
#html5_document(*args, &block) ⇒ Object
Shortcut for Loofah::HTML5::Document.parse(*args, &block)
This method accepts the same parameters as Nokogiri::HTML5::Document.parse
101 102 103 |
# File 'lib/loofah.rb', line 101 def html5_document(*args, &block) Loofah::HTML5::Document.parse(*args, &block) end |
#html5_fragment(*args, &block) ⇒ Object
Shortcut for Loofah::HTML5::DocumentFragment.parse(*args, &block)
This method accepts the same parameters as Nokogiri::HTML5::DocumentFragment.parse
108 109 110 |
# File 'lib/loofah.rb', line 108 def html5_fragment(*args, &block) Loofah::HTML5::DocumentFragment.parse(*args, &block) end |
#scrub_html5_document(string_or_io, method) ⇒ Object
Shortcut for Loofah::HTML5::Document.parse(string_or_io).scrub!(method)
113 114 115 |
# File 'lib/loofah.rb', line 113 def scrub_html5_document(string_or_io, method) Loofah::HTML5::Document.parse(string_or_io).scrub!(method) end |
#scrub_html5_fragment(string_or_io, method) ⇒ Object
Shortcut for Loofah::HTML5::DocumentFragment.parse(string_or_io).scrub!(method)
118 119 120 |
# File 'lib/loofah.rb', line 118 def scrub_html5_fragment(string_or_io, method) Loofah::HTML5::DocumentFragment.parse(string_or_io).scrub!(method) end |