question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Embedded images are ignored

See original GitHub issue

I had to use the following to have embedded images display:

let options = {
  renderNode: {
    'embedded-asset-block': (node) =>
      `<img class="img-fluid" src="${node.data.target.fields.file.url}"/>`
  }
}
let bodyHTML = body ? documentToHtmlString(body, options) : ''

Seems like this should be a default (minus that bootstrap class); out-of-the-box, images didn’t display for me.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:38
  • Comments:43 (2 by maintainers)

github_iconTop GitHub Comments

39reactions
grgcnnrcommented, Apr 19, 2019

Try deleting Gatsby’s .cache folder. There’s an issue with relaonships and caching in the plug-in that I don’t really understand 😉

36reactions
grgcnnrcommented, Mar 24, 2019

Here’s a stripeed down example of how i’m doing it with documentToReactComponents Example of embedded assets and a ‘blockquote’ content type

import { BLOCKS, MARKS, INLINES } from '@contentful/rich-text-types';
import { documentToReactComponents } from '@contentful/rich-text-react-renderer';
import React from "react";

import BlockQuote from "./Blockquote";

const richTextOptions = {
  renderNode: {
    [BLOCKS.EMBEDDED_ASSET]: (node) => {
      const { title, description, file } = node.data.target.fields;
      const mimeType = file['en-US'].contentType
      const mimeGroup = mimeType.split('/')[0]

      switch (mimeGroup) {
        case 'image':
          return <img
            title={ title ? title['en-US'] : null}
            alt={description ?  description['en-US'] : null}
            src={file['en-US'].url}
          />
        case 'application':
          return <a
            alt={description ?  description['en-US'] : null}
            href={file['en-US'].url}
            >{ title ? title['en-US'] : file['en-US'].details.fileName }
          </a>
        default:
          return <span style={{backgroundColor: 'red', color: 'white'}}> {mimeType} embedded asset </span>
      }
      
    },
    [BLOCKS.EMBEDDED_ENTRY]: (node) => {
      const fields = node.data.target.fields;
      switch (node.data.target.sys.contentType.sys.id) {
        case 'blockquote':
          return <div>
            <BlockQuote quoteText={fields.quoteText['en-US']} quoter={fields.quoter['en-US']}/>
          </div>
        default:
          return <div>??????????????? {title} </div>

      }
    },
  }
}

let ContentfulRichText = function(text){
  return documentToReactComponents(JSON.parse(text.text), richTextOptions)
}

export default ContentfulRichText

Blockquote component

const BlockQuote = ({quoteText, quoter}) => {
  return (
    <blockquote>
      {quoteText}
      <footer>
        <cite>{quoter}</cite>
      </footer>
    </blockquote>
  )
}

export default BlockQuote

Read more comments on GitHub >

github_iconTop Results From Across the Web

EXIF Orientation data of embedded image is ignored - GitLab
EXIF Orientation data of embedded image is ignored ... The embedded image should be rotated according to the EXIF Orientation information.
Read more >
Ignoring Small Embedded Previews in RAW Images
Some RAW formats use small embedded preview images. You can configure IMatch to use only previews above a certain size threshold and the...
Read more >
Ignores embedded images references (aka cid) in CSS style ...
This mail shows Thunderbird reads the embedded style sheet, renders images inserted with IMG tag but ignores backgrounds set by css attribute.
Read more >
How to ignore embedded jpeg image data in HTML using ...
import requests from bs4 import BeautifulSoup r = requests.get( 'https://www.sec.gov/Archives/edgar/data/2488/0000002488-18-000043.txt') ...
Read more >
How to ignore attachments(images) embed in mail body - Studio
I need download only the actual attachment need to ignore embed images in mail body, looking for exports suggetions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found