Class: Decidim::ContentParsers::InlineImagesParser

Inherits:
BaseParser
  • Object
show all
Defined in:
lib/decidim/content_parsers/inline_images_parser.rb

Overview

A parser that searches for inline images in an html content and replaces them with EditorImage attachments. Note that rewrite method may create EditorImage instances

Constant Summary

Constants inherited from BaseParser

BaseParser::Metadata

Instance Attribute Summary

Attributes inherited from BaseParser

#content, #context

Instance Method Summary collapse

Methods inherited from BaseParser

#initialize, #metadata

Methods included from Decidim::ContentProcessor::Common

#html_content?, #html_fragment

Constructor Details

This class inherits a constructor from Decidim::ContentParsers::BaseParser

Instance Method Details

#inline_images?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/decidim/content_parsers/inline_images_parser.rb', line 19

def inline_images?
  parsed_content.search(:img).find do |image|
    image.attr(:src).start_with?(%r{data:image/[a-z]{3,4};base64,})
  end
end

#rewriteString

Returns the content with the inline images replaced.

Returns:

  • (String)

    the content with the inline images replaced.



12
13
14
15
16
17
# File 'lib/decidim/content_parsers/inline_images_parser.rb', line 12

def rewrite
  return content unless inline_images?

  replace_inline_images
  parsed_content.to_html
end