0

I am adding HTML in CMS block editor but it keeps removing <a> tags from Html.

Does anyone have a solution for this?

Thanks

  • This is Magento's issue which is still open. #4536 – Aditya Shah Apr 22 at 7:55
  • So, we don't have any solution for now? – Shiwani Apr 22 at 7:59
  • To fix this, You need to fix your HTML and TinyMCE will not complain. In this case, try replacing the <div> tags with <span> tags, as <div> tags are (officially) not valid inside <a> tags, as they are not in-line elements. TinyMCE does not like that, so it just removes the <a> tag for you. – Aditya Shah Apr 22 at 8:00
  • In Magento 2.3 there will be releasing an upgrade to TinyMCE to boost us to v4. This means we could then enable allow_html_in_named_anchor (tinymce.com/docs/configure/content-filtering/…) to resolve the issue with anchor specifically. – Aditya Shah Apr 22 at 8:00
  • can you paste your html code here? – Satish Dubariya Apr 22 at 8:54
3

One of the possible solution for this

Go this file: lib/web/mage/adminhtml/wysiwyg/tiny_mce/html5-schema.js

Replace this:

['a', 'href target rel media hreflang type charset name rev shape coords download', phrasingContent],

With this:

['a', 'href target rel media hreflang type charset name rev shape coords download', flowContent],

Good approach to override this file is you can do this some thing like that

app/design/adminhtml/YourCustomthemeName/Backend/web/mage/adminhtml/wysiwyg/tiny_mce/html5-schema.js

The reason this fixes the issue is that the flowContent array includes block level tags and inline tags unlike the phrasingContent array which includes only inline elements.

The first element of this array is the a the tag we want to fix, the second array entry appears to be attributes allowed on a tags, and the third array entry (the one we care about) appears to be allowed children.

Another solution is to update Magento version to 2.3 because Magento 2.3 will finally have an update to Tinymce 4.x as @Aaditya suggested you in comment.

https://github.com/magento/magento2/blob/2.3-develop/lib/web/tiny_mce_4/tinymce.min.js

I hope this will help I hope this will help

  • Thanks for the reply. Where I can find this 'html5-schema.js' in core files? I am working on Magento2.3 – Shiwani Apr 22 at 9:22
  • I shared the path in answer as well. You have to go to YourMagentofolder/lib/web/mage/adminhtml/wysiwyg/tiny_mce/html5-schema.js – Muhammad Hasham Apr 22 at 9:31
  • @Shiwani have you found the file? if yes then in order to test that changes work, just do answer mentioned changes in core file html5-schema.js. After it resolved issue then after override the file the way, I described in the answer – Muhammad Hasham Apr 22 at 10:15
  • No, This is not working. I override the file and run the commands. – Shiwani Apr 22 at 10:30
  • Don't override it, just edit the core file YourMagentofolder/lib/web/mage/adminhtml/wysiwyg/tiny_mce/html5-schema.js and run the commands. check whether changes resolve the issue or not if yes then try to override the file because there may be the issue in directory structure in overriding the file – Muhammad Hasham Apr 22 at 10:32
0

I was also facing this issue, this can be solved by configuring valid_elements and valid_children settings inside Tinymce4Adapter.js file(for TinyMCE version 4.6)

As answered by https://magento.stackexchange.com/users/77224/mike-dubs here Magento 2.3 - TinyMCE4 Toolbar and Plugin Configuration create the module as mentioned there and add below code inside Config plugin file to provide valid_elements and valid_children settings to Tinymce4Adapter.js as shown below

$settings['valid_elements'] = '*[*]';
$settings['valid_children'] = '+body[style],+div[a],+p[strong|a|#text],+a[div]';

Thanks!

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.