Answers.Body: <p>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 <strong>Purify HTML?</strong> option on the Rich Text field, the <code>figcaption</code> element persisted after saves.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-06T00:47:41.787Z
Answers.Text: 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)
Answers.UserDisplayName: biko
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-06T00:59:50.697Z
Answers.Text: 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.
Answers.UserDisplayName: biko
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-06T10:00:28.860Z
Answers.Text: @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.
Answers.UserDisplayName: Stephen Hamilton
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-06T10:14:54.170Z
Answers.Text: @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.
Answers.UserDisplayName: Stephen Hamilton
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-06T10:30:44.457Z
Answers.Text: @biko Because the redactor settings files are JSON, you can't use callbacks in that file so hooks are out of the question. You could create a custom Redactor plugin to do some processing on save and load it with the following Craft plugin: https://github.com/elliotlewis/Redactor-Extras
  
  Sorry, not a perfect solution I'm afraid!
Answers.UserDisplayName: Stephen Hamilton
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-06T23:50:30.673Z
Answers.Text: 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 https://craftcms.uservoice.com/forums/285224-bugs/suggestions/16532455-redactor-image-caption-not-saved-and-formatting-lo
Answers.UserDisplayName: biko
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-29T17:22:42.250Z
Answers.Text: Feature requests for Redactor have been moved to https://github.com/craftcms/redactor/issues
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-05T09:11:15.717Z
Answers.LastActivityDate: 2016-10-05T09:11:15.717Z
Answers.UserDisplayName: Stephen Hamilton
Body: <p>In Craft CMS 2.6.2945, I've added the "<code>image</code>" 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 <code>figure</code>/<code>figcaption</code> tags after inspecting it.</p>
  
  <p>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 <code>p</code> tag, followed by the caption in a <code>p</code> tag in the editor, but in no tags in templates as raw html.</p>
  
  <p>Is anyone using captions and having troubles?</p>
  
  <p>Added the following comment:</p>
  
  <blockquote>
    <p>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?</p>
  </blockquote>
  
  <p>Edit: here's the JSON:</p>
  
  <p>I also turned off the HTML purify and clean options but that didn't work out.</p>
  
  <pre><code>{
      "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"]
          }
      }
  }
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-04T06:21:53.827Z
Comments.Text: 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?
Comments.UserDisplayName: biko
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-04T10:07:21.297Z
Comments.Text: 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.
Comments.UserDisplayName: Stephen Hamilton
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-05T00:34:00.287Z
Comments.Text: @StephenHamilton good idea.  Added the options.  Have you used the caption feature with success in the past?
Comments.UserDisplayName: biko
Tags: <redactor><image><editor>
Title: Redactor image caption not saved and formatting lost
ThreadText: # Redactor image caption not saved and formatting lost
  
  (Asked by: username_0 on 2016-10-04)
  
  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"]
          }
      }
  }
  
  ```
  
  **Tags:** redactor, image, editor
  
  > **Comments:**
  > **username_0**: 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?  
  > **username_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.  
  > **username_0**: @username_1 good idea.  Added the options.  Have you used the caption feature with success in the past?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-10-05. Score: 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.
  
  > **Comments:**
  > **username_0**: 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)  
  > **username_0**: 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.  
  > **username_1**: @username_0 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.  
  > **username_1**: @username_0 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.  
  > **username_1**: @username_0 Because the redactor settings files are JSON, you can't use callbacks in that file so hooks are out of the question. You could create a custom Redactor plugin to do some processing on save and load it with the following Craft plugin: https://github.com/elliotlewis/Redactor-Extras  Sorry, not a perfect solution I'm afraid!  
  > **username_0**: 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 https://craftcms.uservoice.com/forums/285224-bugs/suggestions/16532455-redactor-image-caption-not-saved-and-formatting-lo  
  > **username_2**: Feature requests for Redactor have been moved to https://github.com/craftcms/redactor/issues  
  
  ---
  
  