module Loofah

Strings and IO Objects as Input

The following methods accept any IO object in addition to accepting a string:

That IO object could be a file, or a socket, or a StringIO, or anything that responds to read and close.

Constants

HTML

Alias for Loofah::HTML4

VERSION

The version of Loofah you are using

Public Class Methods

document(*args, &block)
Alias for: html4_document
fragment(*args, &block)
Alias for: html4_fragment
html4_document(*args, &block) click to toggle source

Shortcut for Loofah::HTML4::Document.parse(*args, &block)

This method accepts the same parameters as Nokogiri::HTML4::Document.parse

# File lib/loofah.rb, line 75
def html4_document(*args, &block)
  Loofah::HTML4::Document.parse(*args, &block)
end
Also aliased as: document
html4_fragment(*args, &block) click to toggle source

Shortcut for Loofah::HTML4::DocumentFragment.parse(*args, &block)

This method accepts the same parameters as Nokogiri::HTML4::DocumentFragment.parse

# File lib/loofah.rb, line 82
def html4_fragment(*args, &block)
  Loofah::HTML4::DocumentFragment.parse(*args, &block)
end
Also aliased as: fragment
html5_document(*args, &block) click to toggle source

Shortcut for Loofah::HTML5::Document.parse(*args, &block)

This method accepts the same parameters as Nokogiri::HTML5::Document.parse

# File lib/loofah.rb, line 100
def html5_document(*args, &block)
  Loofah::HTML5::Document.parse(*args, &block)
end
html5_fragment(*args, &block) click to toggle source

Shortcut for Loofah::HTML5::DocumentFragment.parse(*args, &block)

This method accepts the same parameters as Nokogiri::HTML5::DocumentFragment.parse

# File lib/loofah.rb, line 107
def html5_fragment(*args, &block)
  Loofah::HTML5::DocumentFragment.parse(*args, &block)
end
html5_support?() click to toggle source
# File lib/loofah.rb, line 6
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) click to toggle source

A helper to remove extraneous whitespace from text-ified HTML

# File lib/loofah.rb, line 168
def remove_extraneous_whitespace(string)
  string.gsub(/\n\s*\n\s*\n/, "\n\n")
end
scrub_document(string_or_io, method)
scrub_fragment(string_or_io, method)
scrub_html4_document(string_or_io, method) click to toggle source

Shortcut for Loofah::HTML4::Document.parse(string_or_io).scrub!(method)

# File lib/loofah.rb, line 87
def scrub_html4_document(string_or_io, method)
  Loofah::HTML4::Document.parse(string_or_io).scrub!(method)
end
Also aliased as: scrub_document
scrub_html4_fragment(string_or_io, method) click to toggle source

Shortcut for Loofah::HTML4::DocumentFragment.parse(string_or_io).scrub!(method)

# File lib/loofah.rb, line 92
def scrub_html4_fragment(string_or_io, method)
  Loofah::HTML4::DocumentFragment.parse(string_or_io).scrub!(method)
end
Also aliased as: scrub_fragment
scrub_html5_document(string_or_io, method) click to toggle source

Shortcut for Loofah::HTML5::Document.parse(string_or_io).scrub!(method)

# File lib/loofah.rb, line 112
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) click to toggle source

Shortcut for Loofah::HTML5::DocumentFragment.parse(string_or_io).scrub!(method)

# File lib/loofah.rb, line 117
def scrub_html5_fragment(string_or_io, method)
  Loofah::HTML5::DocumentFragment.parse(string_or_io).scrub!(method)
end
scrub_xml_document(string_or_io, method) click to toggle source

Shortcut for ::xml_document.scrub!(method)

# File lib/loofah.rb, line 163
def scrub_xml_document(string_or_io, method)
  Loofah.xml_document(string_or_io).scrub!(method)
end
scrub_xml_fragment(string_or_io, method) click to toggle source

Shortcut for ::xml_fragment.scrub!(method)

# File lib/loofah.rb, line 158
def scrub_xml_fragment(string_or_io, method)
  Loofah.xml_fragment(string_or_io).scrub!(method)
end
xml_document(*args, &block) click to toggle source

Shortcut for Loofah::XML::Document.parse(*args, &block)

This method accepts the same parameters as Nokogiri::XML::Document.parse

# File lib/loofah.rb, line 146
def xml_document(*args, &block)
  Loofah::XML::Document.parse(*args, &block)
end
xml_fragment(*args, &block) click to toggle source

Shortcut for Loofah::XML::DocumentFragment.parse(*args, &block)

This method accepts the same parameters as Nokogiri::XML::DocumentFragment.parse

# File lib/loofah.rb, line 153
def xml_fragment(*args, &block)
  Loofah::XML::DocumentFragment.parse(*args, &block)
end