class Swordfish::Node::Paragraph

Public Instance Methods

to_html() click to toggle source
# File lib/swordfish/nodes/paragraph.rb, line 7
def to_html
  if @content
    "<p>#{@content}</p>"
  elsif @children.length == 1 && @children[0].is_a?(Swordfish::Node::Image)
    # If the only child is an image, don't bother putting it in a P tag
    @children.map(&:to_html).join
  else
    text = @children.map(&:to_html).join.strip
    "<p>#{text}</p>" unless text =~ /^[[:space:]]*$/
  end
end