Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Insert module to simplify using images with Markdown filter #884

Open
bugfolder opened this issue Mar 8, 2022 · 2 comments
Open

Add Insert module to simplify using images with Markdown filter #884

bugfolder opened this issue Mar 8, 2022 · 2 comments

Comments

@bugfolder
Copy link
Contributor

This is a follow-up to #796 (comment) and #796 (comment). Copying the description from the latter:

I've tested out the Insert module described by @BWPanda in his blog post. It works very nicely and, I think, eliminates a lot of the tedium that @quicksketch identifies as a sticking point against Markdown. With the Insert module, to add an image to a Markdown-formatted field, you:

  1. Upload the file.
  2. Put your cursor where you want the image.
  3. Click the "Insert" button.
  4. Presto. The Markdown-formatted image code is in place.

That said, there's a bit of preparation that needs to be done on the site to make this work. First, of course, install and enable the Insert module.

Next, to get Markdown-formatted image code, you need to override the image-insert.tpl.php template in the admin theme. I created a simple sub-theme of Seven ("badmin"), put the overridden template file in its templates folder, and set that to be the admin theme (of my local copy of backdropcms.org) to override the template.

Also, to make this work the image file needs to be a field of the content type. The Page content has a Files field already, and we can enable Insert for that field, and it works, but since there is no provision for entering alt or title text with a generic file, there's no alt or title text in the inserted image HTML.

A cleaner solution is to add an Image field to the Page type and then enable Insert for that field. In this case, everything works exactly as desired.

A difference from using the image widget in CKEditor is that when CKeditor uploads an image, it doesn't attach it to the particular content type; it puts all images in One Big Heap. (Personally, when I'm creating page nodes that have bespoke images embedded within them I prefer to have the images attached to the node they go with, but I realize others might not.)

And I realize that adding another field to content types is not something done lightly, since that field will persist forever and we'll now have images in two different places: some in CKEditor's one big heap, some attached to nodes (although that is maybe already the case).

All things considered, though, I think adding the Insert module removes one of the last arguments against Markdown, so I would vote for adding both Markdown and Insert to achieve the least-friction way of adding further content to the *.b.org sites.

@jenlampton noted in #796 (comment),

And on the image issue, I don't think we should add another field to every place that uses the markdown filter. Fortunately, we have another work-around already [upload the image as a file attached to the node using the existin Files field].

@jenlampton
Copy link
Member

Next, to get Markdown-formatted image code, you need to override the image-insert.tpl.php template in the admin theme. I created a simple sub-theme of Seven ("badmin"), put the overridden template file in its templates folder, and set that to be the admin theme (of my local copy of backdropcms.org) to override the template.

What happens when you use insert module with one of the other text formats? Does it still insert the image properly, or does the markdown formatting make that not work properly?

@bugfolder bugfolder changed the title Add Insert module to simply using images with Markdown filter Add Insert module to simplify using images with Markdown filter Apr 3, 2022
@bugfolder
Copy link
Contributor Author

What happens when you use insert module with one of the other text formats? Does it still insert the image properly, or does the markdown formatting make that not work properly?

It inserts both Markdown and HTML versions, so one or the other (or both) work, and you just delete the line that's not applicable. Works with CKEditor, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants