Module: Decidim::ContentProcessor::Common

Included in:
Decidim::ContentParsers::BaseParser, Decidim::ContentRenderers::BaseRenderer
Defined in:
decidim-core/lib/decidim/content_processor.rb

Instance Method Summary collapse

Instance Method Details

#html_content?(fragment = html_fragment) ⇒ Boolean

Reports if the content being processed is in HTML format. The content is interpreted as HTML when it contains one or more HTML tags in it.

Returns:

  • (Boolean)

    a boolean indicating if the content is HTML



159
160
161
162
163
164
# File 'decidim-core/lib/decidim/content_processor.rb', line 159

def html_content?(fragment = html_fragment)
  return false if fragment.children.count.zero?
  return true if fragment.children.count > 1

  fragment.children.first.name != "text"
end

#html_fragment(text = nil) ⇒ Loofah::HTML::DocumentFragment

Turns the content string into a document fragment object. This is useful for parsing the HTML content.

Returns:

  • (Loofah::HTML::DocumentFragment)


170
171
172
173
174
175
176
# File 'decidim-core/lib/decidim/content_processor.rb', line 170

def html_fragment(text = nil)
  if text
    Loofah.fragment(text)
  else
    @html_fragment ||= Loofah.fragment(content)
  end
end