Post cook for images?

AI-generated summary

In the discussion “Post cook for images?”, fearlessfrog is seeking help with embedding images in a post using a server-side plugin. They found that simply adding the image URL to the post’s raw content didn’t render the image preview, but rather showed the plain text URL. However, fearlessfrog later solved the issue by wrapping the image URL in an <img> tag within the raw format, allowing the image to render correctly upon saving the post.

I have a very simple plugin (server-side) I was playing around with.

For this part of the call:

on(:post_created) do |post, params|

I use the post.raw to put some content in:

post.raw = "@#{post.user.username} says hello!\n\n"
post.save

..and it works great. Cool.

My question is how to embed an image, as in the same result as when the post cooks in the preview editor?

If I change it to something like this:

post.raw = "https://cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/optimized/3X/9/d/9d543e92b15b06924249654667a81441a55867eb_1_690x184.png\n\n"
post.save

..then the post shows the plain image address text and not the preview image. If I open edit on the post manually in the UI it works ok (shows the image preview), just not on my post save.

Looking through the code, am I meant to call ‘post.cook’ after the save to trigger this?

Thanks for any help or pointers to examples.

I solved this by putting the image into an IMG tag within the raw format, i.e.

post.raw = "<img src='https://cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/optimized/3X/9/d/9d543e92b15b06924249654667a81441a55867eb_1_690x184.png'/>\n\n"

post.save

..means that it cooks on the save fine now.