Module: Decidim::ContentProcessor::Common
- Defined in:
- lib/decidim/content_processor.rb
Instance Method Summary collapse
-
#html_content?(fragment = html_fragment) ⇒ Boolean
Reports if the content being processed is in HTML format.
-
#html_fragment(text = nil) ⇒ Loofah::HTML::DocumentFragment
Turns the content string into a document fragment object.
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.
159 160 161 162 163 164 |
# File '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.
170 171 172 173 174 175 176 |
# File '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 |