Skip to content

How can I add support for images? #4

Description

@Bodacious

Images don't seem to be working for me.

My post content looks like this:

{
  "entityMap" => {},
  "blocks" => [
    {
      "key" => "an9ha",
      "text" => "Lorem ipsum",
      "type" => "header-one",
      "depth" => 0,
      "inlineStyleRanges" => [],
      "entityRanges" => [],
      "data" => {}
    },
    {
      "key" => "1pi54",
      "text" => "This is a sub-heading",
      "type" => "header-two",
      "depth" => 0,
      "inlineStyleRanges" => [],
      "entityRanges" => [],
      "data" => {}
    },
    {
      "key" => "8vsrd",
      "text" => "",
      "type" => "image",
      "depth" => 0,
      "inlineStyleRanges" => [],
      "entityRanges" => [],
      "data" => {
        "enabled"=>false,
        "aspect_ratio" => {
          "width"=>1000,
          "height"=>878.1838316722037,
          "ratio"=>87.81838316722038
        },
        "width"=>3612,
        "height"=>3172,
        "forceUpload"=>false,
        "url" => "https://s3-eu-west-2.amazonaws.com/reformer-assets/development/images/uploads/eccbc87e4b5ce2fe28308fd9f2a7baf3/resized_e0e2c961df.png",
        "loading_progress"=>100,
        "selected"=>false,
        "loading"=>true,
        "file"=>nil,
        "direction" => "center"
      }
    },
    {
      "key" => "bf99o",
      "text" => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
      "type" => "unstyled",
      "depth" => 0,
      "inlineStyleRanges" => [],
      "entityRanges" => [],
      "data" => {}
    },
    {
      "key" => "2igf",
      "text" => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
      "type" => "unstyled",
      "depth" => 0,
      "inlineStyleRanges" => [],
      "entityRanges" => [],
      "data" => {}
    },
    {
      "key" => "c4o61",
      "text" => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
      "type" => "unstyled",
      "depth" => 0,
      "inlineStyleRanges" => [],
      "entityRanges" => [],
      "data" => {}
    },
    {
      "key" => "b6khi",
      "text" => "",
      "type" => "unstyled",
      "depth" => 0,
      "inlineStyleRanges" => [],
      "entityRanges" => [],
      "data" => {}
    }
  ]
}

My configuration looks like this:

# Convert a record's Dante content into HTML, asynchronously
class DanteToHTML

  require "draftjs_exporter"
  require "draftjs_exporter/entities/link"

  attr_reader :output

  CONFIG = {
    entity_decorators: {
      'LINK' => DraftjsExporter::Entities::Link.new(className: 'link')
    },
    block_map: {
      'header-one'          => { element: 'h1' },
      'header-two'          => { element: "h2" },
      'header-three'        => { element: "h3" },
      'header-four'         => { element: "h4" },

      "image"               => { element: "img" },
      "blockquote"          => { element: "blockquote" },
      "code-block"          => { element: "pre" },
      'unordered-list-item' => {
        element: 'li',
        wrapper: ['ul', { className: 'public-DraftStyleDefault-ul' }]
      },
      'unstyled' => { element: 'p' }
    },
    style_map: {
      "UNDERLINE" => { fontStyle: 'underline' },
      'ITALIC'    => { fontStyle: 'italic' },
      'BOLD'      => { fontStyle: 'bold' }
    }
  }

  def self.exporter
    @exporter ||= DraftjsExporter::HTML.new(CONFIG)
  end

  def initialize(editor_content)
    @output = self.class.exporter.call(editor_content.deep_symbolize_keys)
  end

end

What I expect to see, is a well-formed HTML image tag, with the SRC attribute containing the correct image URL (https://s3-eu-west-2.amazonaws.com/reformer-assets/development/images/uploads/eccbc87e4b5ce2fe28308fd9f2a7baf3/resized_e0e2c961df.png).
Instead, I just see an empty <img> tag floating in my HTML.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions