Class: Mato::HtmlFilters::BareInlineElement

Inherits:
Object
  • Object
show all
Defined in:
lib/mato/html_filters/bare_inline_element.rb

Constant Summary collapse

STANDALONE_INLINE_ELEMENTS =
Set.new([
  "img",
  "input",
  "textarea",
])

Instance Method Summary collapse

Instance Method Details

#call(doc) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/mato/html_filters/bare_inline_element.rb', line 17

def call(doc)
  doc.children.each do |node|
    next unless STANDALONE_INLINE_ELEMENTS.include?(node.name)

    parent = Nokogiri::HTML4.fragment('<p/>')
    parent.child.add_child(node.dup)
    node.replace(parent)
  end
end