magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.54k stars 9.31k forks source link

In WYSIWYG editor, i tags with class but no content are removed. #28698

Open LiamKarlMitchell opened 4 years ago

LiamKarlMitchell commented 4 years ago

Summary (*)

These are used for icons to be shown in some blocks/content and so editing the content causes the icons to be removed.

It probably removes empty spans as well but I have not tried this yet.

Duplicate of #21602 which was closed for no reason. https://github.com/magefan/module-wysiwyg-advanced/issues/13

Preconditions

Magento 2.3.0 Magento 2.4-develop

Examples (*)

Steps to Reproduce

Edit a block or page content in the source edit.

<i class="icon-paperclip"></i>

Click show editor. Click hide editor.

Actual Result

And its gone... peek

Expected Result

Tag is not removed

Another example

Test
<i class="footer-icon icon-line-clock"></i>
Test

Becomes

<p>Test Test</p>

You can hack around it with an html comment as content such as

<i class="icon-paperclip"><!-- icon --></i>

But then it gets changed into an em.

<em class="icon-paperclip"><!-- icon --></em>

Font awesome for example uses i tags. In my case, WeltPixel Pearl theme uses i tags, especially their example content that is imported with the theme which we just want to edit/tweak as needed.

Proposed solution

Keep tags if they have no content when there are classes or attributes set. Maybe this should only apply to some tags such as a, i, div, span?

Perhaps not p tags as TinyMCE if I recall litters them all over the place and the removal of empty elements was made to clean up such issues, best if can consider i and span tags as non empty when they have class.


m2-assistant[bot] commented 4 years ago

Hi @LiamKarlMitchell. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

Please, add a comment to assign the issue: @magento I am working on this


LiamKarlMitchell commented 4 years ago

@magento give me 2.4-develop instance

magento-engcom-team commented 4 years ago

Hi @LiamKarlMitchell. Thank you for your request. I'm working on Magento 2.4-develop instance for you

magento-engcom-team commented 4 years ago

Hi @LiamKarlMitchell, here is your Magento instance. Admin access: https://i-28698-2-4-develop.instances.magento-community.engineering/admin_eb47 Login: 2c8b8d46 Password: be56a0e9582a Instance will be terminated in up to 3 hours.

LiamKarlMitchell commented 4 years ago

@magento Confirmed on 2.4-develop image

Entered in the content in source editor.

<p>CMS homepage content goes here.</p>
<p>Icon should be here: <i class="footer-icon icon-line-clock"></i></p>

Click the Show / Hide editor, wait a moment. image

Click the Show / Hide editor again to go back to source editor. image

Content lacks the "icon" element.

<p>CMS homepage content goes here.</p>
<p>Icon should be here:</p>
LiamKarlMitchell commented 4 years ago

Issue: Confirmed

laurnts commented 4 years ago

This is because somehow not an entirely recognized html tag by tinymce. And tinymce also remove an empty html tag because it's "empty".

At this moment I am using <em class="fa">&nbsp;</em> this should work just fine.

thorrrr commented 4 years ago

HI Guys not sure if this helps i past in code for a sales template which i always used in M1 no issue. But in M2 50 lines are stripped out which screws up my listing template Actual Script Pasted into Policy.txt M2E Stripped Out from Policy.txt

Is there a fix to stop this occurring

danielpugh commented 4 years ago

This an issue for me on 2.3.5p2 It is a common problem might be useful https://github.com/claviska/tinymce-iconfonts

Or perhaps

tinyMCE.init({ // ... extended_valid_elements : '[]', });

danielpugh commented 4 years ago

following last post i have installed the tinymce plugin mentioned above (tinymce-iconfonts) and it allows me to use e.g. font-awesome immediately. had to edit file to add plugin as per here - https://devdocs.magento.com/guides/v2.4/ui_comp_guide/components/wysiwyg/configure-tinymce-editor.html

added plugin to this file /vendor/magento/module-cms/Model/Wysiwyg/DefaultConfigProvider.php then uploaded the two files and deployed static content (finding location took some time, but hint on the tinymce page which shows the location it is expecting file)

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

LiamKarlMitchell commented 3 years ago

Yes still a problem stale bot.

m2-assistant[bot] commented 3 years ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

magento-engcom-team commented 3 years ago

:white_check_mark: Confirmed by @engcom-Bravo Thank you for verifying the issue. Based on the provided information internal tickets MC-40681 were created

Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

dverkade commented 3 years ago

Posting a comment. Issues should not be automatically closed.

iphigenie commented 3 years ago

There really should be a "built in" way to extend the tinymce options as part of setting up a Magento 2 site.

Currently it warns that things like aria, role etc won't be allowed (why? I would like my CMS content to be as accessibility tagged properly!

And adding icons without having to nbsp them...

iphigenie commented 3 years ago

following last post i have installed the tinymce plugin mentioned above (tinymce-iconfonts) and it allows me to use e.g. font-awesome immediately. had to edit file to add plugin as per here - https://devdocs.magento.com/guides/v2.4/ui_comp_guide/components/wysiwyg/configure-tinymce-editor.html

added plugin to this file /vendor/magento/module-cms/Model/Wysiwyg/DefaultConfigProvider.php then uploaded the two files and deployed static content (finding location took some time, but hint on the tinymce page which shows the location it is expecting file)

Thanks to @danielpugh 's hints I dabbled a minimal implementation to integrate https://github.com/claviska/tinymce-iconfonts and at first glance it's working - though if I missed something someone please shout :)

my module is Alpine/AlpineCustom

js plugin files uploaded to lib/web/tiny_mce_4/plugins/iconfonts

a di.xml for adminhtml

        <plugin name="Alpine_AlpineCustom" type="Alpine\AlpineCustom\Plugin\Model\Cms\ExtendDefaultConfigProvider" />
    </type>

the plugin ExtendDefaultConfigProvider.php

namespace Alpine\AlpineCustom\Plugin\Model\Cms;
use Magento\Cms\Model\Wysiwyg\DefaultConfigProvider;

class ExtendDefaultConfigProvider 
{
/**
 * @param \Magento\Cms\Model\Wysiwyg\DefaultConfigProvider $subject
 * @param \Magento\Framework\DataObject $result
 * @return \Magento\Framework\DataObject $result
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
    public function afterGetConfig(\Magento\Cms\Model\Wysiwyg\DefaultConfigProvider $subject, \Magento\Framework\DataObject $result)
    {
        $plugins = "". $result['tinymce4']['plugins'] ;
        $tinymceconfig = $result['tinymce4'];
        $tinymceconfig['plugins'] = $plugins  .' iconfonts';
        $result['tinymce4'] = $tinymceconfig;
        return $result;
    }
}

seems to allow i to stay empty, but alas it "eats" the style tag so modern fontawesome options arent possible - I mean it's an old plugin!

Definitely going to look at extending tinymce configuration to allow more tags as per https://github.com/magento/community-features/issues/326

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 28 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

Meberem commented 3 years ago

@stalebot this is still a problem

engcom-Bravo commented 4 months ago

Hi @LiamKarlMitchell,

Thanks for your reporting and collaboration.

We have verified the issue in Latest 2.4-develop instance and the issue is reproducible.Kindly refer the attached video.

https://github.com/magento/magento2/assets/51680745/b6e73b97-647b-4a43-833c-8abead9bfc04

Tags getting removed.

Hence Confirming the issue.

Thanks.

LiamKarlMitchell commented 4 months ago

Yep its been an issue for years, no traction

github-jira-sync-bot commented 4 months ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-12301 is successfully created for this GitHub issue.

m2-assistant[bot] commented 4 months ago

:white_check_mark: Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.