4

In Craft CMS 2.6.2945, I've added the "image" button in the Redactor config. In the editor, I've added an image and added a caption (by clicking the inserted image). When the image is saved, the caption shows up properly and I could see that it was set as figure/figcaption tags after inspecting it.

However, after saving the entry (save and continue editing doesn't even work now as it takes you to the Entries page), the formatting gets lost and the image ends up in a p tag, followed by the caption in a p tag in the editor, but in no tags in templates as raw html.

Is anyone using captions and having troubles?

Added the following comment:

After some more testing and debugging, I'm noticing that Redactor is outputting malformed HTML. The img is going in a p tag, following by a figcaption tag. Since my rich text field was set up to clean malformed HTML, saving the entry would get rid of the orphaned figcaption tag. Any ideas why the img is not going in a figure tag?

Edit: here's the JSON:

I also turned off the HTML purify and clean options but that didn't work out.

{
    "buttons": ["format","bold","lists","link","file","image"],
    "plugins":["video","source"],
    "toolbarFixed": true,
    "formatting": ["p", "blockquote", "h2", "h3", "h4", "h5", "h6"],
    "formattingAdd": {
        "para-intro": {
            "title": "Paragraph Intro",
            "args": ["p", "class", "intro", "toggle"]
        },
        "caption": {
            "title": "Caption",
            "args": ["p", "class", "cap"]
        }
    }
}
  • After some more testing and debugging, I'm noticing that Redactor is outputting malformed HTML. The img is going in a p tag, following by a figcaption tag. Since my rich text field was set up to clean malformed HTML, saving the entry would get rid of the orphaned figcaption tag. Any ideas why the img is not going in a figure tag? – biko Oct 4 '16 at 6:21
  • 1
    Maybe worth stating the options you have for your field too. For example, Clean up HTML? and Purify HTML? may be interfering with the image/figure tags. – Stephen Hamilton Oct 4 '16 at 10:07
  • @StephenHamilton good idea. Added the options. Have you used the caption feature with success in the past? – biko Oct 5 '16 at 0:34
4

I copied your Redactor settings to a clean installation of Craft (2.6.2945) and added an image to a Rich Text field set to use those specific settings. Initially I encountered the same behaviour. However, unlike in your experience, after disabling the Purify HTML? option on the Rich Text field, the figcaption element persisted after saves.

  • Thanks for your effort and time on this. After disabling that feature, the figcaption element would stay but it wasn't wrapped in any figure element. It would be p > img + figcaption. Can you confirm that the figure element was there as well? (I also created another test field and the problem persisted) – biko Oct 6 '16 at 0:47
  • If the HTML is properly generated and saved, clicking on the image should have the correct Caption field filled in. I noticed that on the redactor homepage. Right now, only the Title field is being saved correctly since it's probably reading the image title attribute. – biko Oct 6 '16 at 0:59
  • @biko just tested and have the same results (i.e. the figcaption element remains but the Caption field in the image popup is blank after saving), will see what I can "figure" out - no pun intended. – Stephen Hamilton Oct 6 '16 at 10:00
  • @biko Craft overwrites the image modal instance usually provided by Redactor with it's own code which doesn't include the figure element (using developer tools or via (S)FTP, view the RichTextInput.js file, you can see them hooking the image button there to integrate with their in-built assets). So, I'd look at overwriting/extending their hook to include a figure element or ask them to update this in future as a bug fix. – Stephen Hamilton Oct 6 '16 at 10:14
  • 1
    Thanks very much for looking into this! Yeah too bad that there isn't a quick and easy solution. I've filed a bug at craftcms.uservoice.com/forums/285224-bugs/suggestions/… – biko Oct 6 '16 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.