Class: Decidim::ContentParsers::InlineImagesParser
- Inherits:
-
BaseParser
- Object
- BaseParser
- Decidim::ContentParsers::InlineImagesParser
- 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
Instance Attribute Summary
Attributes inherited from BaseParser
Instance Method Summary collapse
- #inline_images? ⇒ Boolean
-
#rewrite ⇒ String
The content with the inline images replaced.
Methods inherited from BaseParser
Constructor Details
This class inherits a constructor from Decidim::ContentParsers::BaseParser
Instance Method Details
#inline_images? ⇒ 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 |
#rewrite ⇒ String
Returns 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 |