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

Link on image is lost after loading the content with GHS enabled #12831

Closed
Schwammerl11 opened this issue Nov 11, 2022 · 3 comments · Fixed by #14697
Closed

Link on image is lost after loading the content with GHS enabled #12831

Schwammerl11 opened this issue Nov 11, 2022 · 3 comments · Fixed by #14697
Assignees
Labels
package:html-support squad:core Issue to be handled by the Core team. support:2 An issue reported by a commercially licensed client. type:bug This issue reports a buggy (incorrect) behavior.

Comments

@Schwammerl11
Copy link

Schwammerl11 commented Nov 11, 2022

EDITED:

📝 Provide detailed reproduction steps (if any)

  1. Load an image into an editor (in which GHS is enabled + allow all)
  2. Add a link to the image via the LinkImage plugin
  3. Save the editor's data by running editor.setData( editor.getData() ) in the browser's console
  4. Retrieve the data via editor.getData()
  5. Observe that the <a> tag is stripped in the data retrieved

📃 Other details

Disabling GHS makes this works as expected i.e. the link is retained. Tested this using our linkimage manual test with the GeneralHtmlSupport plugin enabled.

This doesn't seem to be a regression (at least not a recent one) since it exists as far back as v30.0.0 of the editor.

ORIGINAL POST:

📝 Provide detailed reproduction steps (if any)

  1. Load image in editor (base64)
  2. Add link to image
  3. Save and close editor
  4. Link tag is correctly generated as HTML and URL can be opened
  5. Reopen editor
  6. Link is not shown in editor
  7. When content is saved again, the link is lost

✔️ Expected result

Link should show up in editor and be editable

❌ Actual result

Link does not show up in editor and is therefore lost when content is saved again

📃 Other details

HTML Code on which editor is initialized upon, link tag included
image

Editor source code, link tag omitted
image

Example code, use toggle button to show/hide editor
https://codepen.io/schwammerl11/pen/mdKWaoV

  • Browser: Google Chrome v107.0.5304.89
  • OS: Windows 11 v21H2 (22000. 1098)
  • First affected CKEditor version: 35.1.0
  • Installed CKEditor plugins: [
    "Alignment",
    "Autoformat",
    "AutoImage",
    "AutoLink",
    "Autosave",
    "Base64UploadAdapter",
    "BlockQuote",
    "Bold",
    "CloudServices",
    "Code",
    "CodeBlock",
    "DataFilter",
    "DataSchema",
    "Essentials",
    "FindAndReplace",
    "FontBackgroundColor",
    "FontColor",
    "FontFamily",
    "FontSize",
    "GeneralHtmlSupport",
    "Heading",
    "Highlight",
    "HorizontalLine",
    "HtmlComment",
    "HtmlEmbed",
    "Image",
    "ImageCaption",
    "ImageInsert",
    "ImageResize",
    "ImageStyle",
    "ImageToolbar",
    "ImageUpload",
    "Indent",
    "IndentBlock",
    "Italic",
    "Link",
    "LinkImage",
    "List",
    "ListProperties",
    "MediaEmbed",
    "MediaEmbedToolbar",
    "Mention",
    "PageBreak",
    "Paragraph",
    "PasteFromOffice",
    "RemoveFormat",
    "SourceEditing",
    "SpecialCharacters",
    "SpecialCharactersArrows",
    "SpecialCharactersCurrency",
    "SpecialCharactersLatin",
    "SpecialCharactersMathematical",
    "SpecialCharactersText",
    "StandardEditingMode",
    "Strikethrough",
    "Style",
    "Subscript",
    "Superscript",
    "Table",
    "TableCaption",
    "TableCellProperties",
    "TableColumnResize",
    "TableProperties",
    "TableToolbar",
    "TextPartLanguage",
    "TextTransformation",
    "Title",
    "TodoList",
    "Underline",
    "WordCount"
    ]

If you'd like to see this fixed sooner, add a 👍 reaction to this post.

@Schwammerl11 Schwammerl11 added the type:bug This issue reports a buggy (incorrect) behavior. label Nov 11, 2022
@Schwammerl11
Copy link
Author

Schwammerl11 commented Dec 14, 2022

Temporary fix:

Somehow the editor does not break the link when it's not contained within FIGURE but is the parent of FIGURE instead.
The following code does just that and firstly moves every child node of A to FIGURE, then inserts A to where FIGURE was before appending FIGURE to A.
Add this before initializing your editor.

richtext.querySelectorAll('figure > a').forEach(a => {
  let f = a.parentNode;
  Array.from(a.children).forEach(c => f.appendChild(c));
  f.parentNode.insertBefore(a, f);
  a.appendChild(f);
});
        
ClassicEditor.create( richtext, ...

@mabryl mabryl added squad:core Issue to be handled by the Core team. package:html-support labels Dec 19, 2022
@mabryl mabryl changed the title Link on image not initialized Link on image is lost after loading the content with GHS enabled Dec 19, 2022
@mabryl
Copy link
Contributor

mabryl commented Dec 19, 2022

Hi @Schwammerl11,

Thanks for reaching out and for bringing this issue to our attention. We can confirm that it does indeed occur and seems to be related to the GeneralHtmlSupport plugin.

I took the liberty of changing your post's title and adding my troubleshooting steps to the top of it to make it a little bit easier for our devs to tackle this issue. Hope you don't mind.

Feel free to continue participating in this thread if you have anything else to share.

Once again, thank you for using our editor and helping us make it better 🙂

@aldonace-wu aldonace-wu added the support:2 An issue reported by a commercially licensed client. label Jun 14, 2023
@Witoso
Copy link
Member

Witoso commented Jul 10, 2023

Refinement: to check the order of upcast conversion when GHS and LinkImageis enabled.

@CKEditorBot CKEditorBot added status:planned Set automatically when an issue lands in the "Sprint backlog" column. We will be working on it soon. and removed status:planned Set automatically when an issue lands in the "Sprint backlog" column. We will be working on it soon. labels Jul 24, 2023
@mmotyczynska mmotyczynska self-assigned this Jul 26, 2023
@CKEditorBot CKEditorBot added status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. and removed status:planned Set automatically when an issue lands in the "Sprint backlog" column. We will be working on it soon. labels Jul 26, 2023
@CKEditorBot CKEditorBot added status:planned Set automatically when an issue lands in the "Sprint backlog" column. We will be working on it soon. status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. and removed status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. status:planned Set automatically when an issue lands in the "Sprint backlog" column. We will be working on it soon. labels Jul 31, 2023
arkflpc added a commit that referenced this issue Aug 3, 2023
…hen-ghs-enabled

Fix (html-support): Link on image should not be lost when loading content with `LinkImage` and full GHS enabled. Closes #12831.
@CKEditorBot CKEditorBot removed the status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. label Aug 3, 2023
@CKEditorBot CKEditorBot added this to the iteration 66 milestone Aug 3, 2023
pomek pushed a commit that referenced this issue Aug 8, 2023
…hen-ghs-enabled

Fix (html-support): Link on image should not be lost when loading content with `LinkImage` and full GHS enabled. Closes #12831.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:html-support squad:core Issue to be handled by the Core team. support:2 An issue reported by a commercially licensed client. type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants