Class: Loofah::Scrubbers::NewlineBlockElements

Inherits:
Loofah::Scrubber show all
Defined in:
lib/loofah/scrubbers.rb

Overview

This class probably isn’t useful publicly, but is used for #to_text’s current implemention

Constant Summary

Constants inherited from Loofah::Scrubber

Loofah::Scrubber::CONTINUE, Loofah::Scrubber::STOP

Instance Attribute Summary

Attributes inherited from Loofah::Scrubber

#block, #direction

Instance Method Summary collapse

Methods inherited from Loofah::Scrubber

#append_attribute, #traverse

Constructor Details

#initializeNewlineBlockElements

:nodoc:



240
241
242
# File 'lib/loofah/scrubbers.rb', line 240

def initialize # rubocop:disable Lint/MissingSuper
  @direction = :bottom_up
end

Instance Method Details

#scrub(node) ⇒ Object



244
245
246
247
248
249
250
251
252
253
254
# File 'lib/loofah/scrubbers.rb', line 244

def scrub(node)
  return CONTINUE unless Loofah::Elements::LINEBREAKERS.include?(node.name)

  replacement = if Loofah::Elements::INLINE_LINE_BREAK.include?(node.name)
    "\n"
  else
    "\n#{node.content}\n"
  end
  node.add_next_sibling(Nokogiri::XML::Text.new(replacement, node.document))
  node.remove
end