backdrop-contrib / tinymce

Integration for the TinyMCE editor in Backdrop CMS
https://backdropcms.org/project/tinymce
GNU General Public License v2.0
2 stars 1 forks source link

Allowed HTML tags vs. Default profile #2

Closed olafgrabienski closed 1 year ago

olafgrabienski commented 1 year ago

The Default editor profile doesn't respect the text format filter setting "Limit allowed HTML tags". That means, it's possible to choose HTML tags that are not allowed by default in Backdrop's Filtered HTML format, e.g. <h2>, which then aren't displayed in the rendered content.

(In contrast, the Small profile seems to respect the setting.)

indigoxela commented 1 year ago

Hey, thanks for chiming in and testing. :smile:

The allowed_html handling is:

  1. Work in progress :wink:
  2. Will be slightly different from what we're used to with CKE

Stay tuned.

indigoxela commented 1 year ago

Handling of allowed_html is now available. No update hook, but if you update your tinymce.profile.* in your active config directory, things might also work (after updating code).

olafgrabienski commented 1 year ago

@indigoxela Thanks for the update! Work in progress sounds good.

After updating the code and the config files I had first the impression that the behavior was the same as before: I was still able to choose HTML tags that are not allowed by default in Backdrop's Filtered HTML format, like <h2>.

However, I have missed something (not sure if I missed it even before, or if it looked different): After editing the "Limit allowed HTML tags" configuration of the Default profile, I see the following addition to the description text:

Based on the text editor configuration, these tags have automatically been added: <h2> <pre> <div> <span>.

And as far I can tell, it's not possible to remove such (automatically added) tags for a given profile manually. Is this the intended behavior?

indigoxela commented 1 year ago

After updating the code and the config files I had first the impression that the behavior was the same as before:

My instructions for updating were pretty misleading, I guess. :wink:

You have to save the admin settings at least once.

But in the meantime, a lot of code changed. It's probably better, to start fresh, anyway.

indigoxela commented 1 year ago

And as far I can tell, it's not possible to remove such (automatically added) tags for a given profile manually. Is this the intended behavior?

The editor profile requires these tags - it's defined in the json file.

If you want to remove tags, you have to create a custom profile - which:

  1. removes the tags from filter_allowed_html
  2. remove the plugins that will set those tags (plugins)
  3. or - update the style_formats accordingly (depends on the tags you want to get rid of)

This behavior is pretty close to what the CKE4 module does, which requires the tags for all the enabled toolbar items. Only that there's no drag-and-drop for single buttons in this module here.

olafgrabienski commented 1 year ago

Interesting, I'll have a closer look at the JSON files, to understand the profiles!

indigoxela commented 1 year ago

Interesting, I'll have a closer look at the JSON files, to understand the profiles!

They're very flexible, as TinyMCE provides lots of options (oh, so many options...).

The benefit of a custom profile: it's config – create it once, re-use on other sites via export/import (Configuration manager, "Editor profiles"). :wink:

olafgrabienski commented 1 year ago

Great, I just created a custom profile, by adapting the Default profile and importing it via Backdrop's configuration manager. That worked fine, at first sight. I was however not sure, which plugins provide (or require) which style_formats. Is this documented somewhere in the TinyMCE documentation?

indigoxela commented 1 year ago

Is this documented somewhere in the TinyMCE documentation?

So far, I'm not aware of such documentation.

In fact, I'm not even sure, if CKE documents its tags somewhere. The list for the filter module comes from Backdrop code in hook_ckeditor_plugins.

For which Tiny plugins do you need the info?

olafgrabienski commented 1 year ago

For which Tiny plugins do you need the info?

In the default profile, I'm interested to know which plugin wants to use the <span> tag.

indigoxela commented 1 year ago

In the default profile, I'm interested to know which plugin wants to use the tag.

AFAIK the "underline" format uses spans.

Edit: oops, but it uses inline-styles, which means, the underline will never show up. :thinking: The filter module usually strips out all inline styles and setting attributes via UI is broken (core).

indigoxela commented 1 year ago

Seems like the formats are also fully configurable - you can limit to the ones you need and map them to classes if desired. https://www.tiny.cloud/docs/tinymce/6/content-formatting/#formats

izmeez commented 1 year ago

I see the profile builder on the latest iteration of the module. It looks good. I am wondering if there is a reason why it does not allow changing the existing profiles like "Default" and "Small"?

indigoxela commented 1 year ago

I am wondering if there is a reason why it does not allow changing the existing profiles

@izmeez I think, I can explain that. The builder already needs more code, than the module functionality itself. :wink: As TinyMCE provides loads of additional options, the risk is high to break people's previous customizations by overriding. So I decided to not provide it.

izmeez commented 1 year ago

@indigoxela Thank you for the explanation. I am wondering, if it's not too much effort, is it possible to provide a display of the allowed tags in the currently selected profile, similar to what the ckeditor module does. Then in the case of the the existing profiles it might include a note: only custom profiles can be overridden.

indigoxela commented 1 year ago

is it possible to provide a display of the allowed tags in the currently selected profile

The CKEditor module doesn't display that. Buttons just add their dependencies to the "Limit allowed HTML tags". Just like the TinyMCE module does via profiles. Very similar, actually, but on different places. And that's by intention.

... only custom profiles can be overridden.

I won't implement that. The builder could break manually adapted profiles, so it simply makes no sense. And also the effort's too big for something you might eventually need once. :wink:

olafgrabienski commented 1 year ago

@indigoxela Thank you very much for the Profile Builder which helps a lot to understand how the Editor profiles work. I hadn't much time lately to experiment with different settings, but it looks much more easy now to build a custom profile. With the profile builder and related information in the Wiki, I think this issue here can however be closed.