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

Tinymce customization #1807

Merged
merged 6 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/classic-ui/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static-resources
template-global-variables
templates
theming/index
tinymce-customization
viewlets
views
whatsnew
Expand Down
87 changes: 87 additions & 0 deletions docs/classic-ui/tinymce-customization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
myst:
html_meta:
"description": "TinyMCE customization in Plone 6"
"property=og:description": "TinyMCE customization in Plone 6"
"property=og:title": "TinyMCE customization in Plone 6"
"keywords": "Plone 6, Classic UI, Bootstrap 5, TinyMCE, customization"
---

(classic-ui-tinymce-customization-label)=

# TinyMCE customization

This chapter is a developer reference manual for customizing {term}`TinyMCE`.


## Customize {menuselection}`Format` menu

There are several options to customize TinyMCE's {menuselection}`Format --> Formats` menu.

The first two options use TinyMCE's [`formats` JSON configuration](https://www.tiny.cloud/docs/tinymce/latest/content-formatting/).
They are less complicated to implement than the third option.


### Add-on GenericSetup configuration file

This option is best for system administrators and developers who write their own add-ons to ease reproducibility.

You can add a GenericSetup configuration file to your add-on, such as {file}`profiles/default/registry/tinymce.xml`, with the following content.

```xml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about

  <records interface="Products.CMFPlone.interfaces.ITinyMCESchema" prefix="plone">
    <value key="other_settings">
      {
        "extended_valid_elements":"i[class],script[type|src]",
        "style_formats": [
          {
            "title": "Highlight",
            "block": "p",
            "attributes": {
              "class": "featured"
            }
          },
          {
            "title": "Alert",
            "block": "p",
            "attributes": {
              "class": "redalert"
            }
          }
        ],
        "style_formats_merge": true
      }
    </value>
  </records>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beware: other_settings will override all previously made settings. This is meant to inject settings which are not populated in other config fields.

And the style_formats_merge options provides the default "tinymce styles" but that's not exactly the same as the plone default tinymce styles ...

<registry>
<records interface="plone.base.interfaces.controlpanel.ITinyMCESchema"
prefix="plone">
<value key="formats"
purge="true"
>{
"myformat": {
"block": "div",
"classes": "my-css-classes"
}
}</value>
</records>
</registry>
```


### Edit the `Formats` option in the TinyMCE control panel

This option is good for quick edits, but is not as reproducible as the GenericSetup option.

You can manually customize the `Formats` value through-the-web in the TinyMCE control panel.

1. Navigate to {menuselection}`Site Setup --> TinyMCE --> Default`, or append `@@tinymce-controlpanel` to the root of your website in your browser's location bar.
1. Scroll down to {guilabel}`Formats`, and edit the JSON configuration.
1. Click the {guilabel}`Save` button.



### Inject formats with files named {file}`tinymce-formats.css`

This option is more complex to implement than the previous options.

In Plone 6, TinyMCE has a special logic that automatically reads registered files named {file}`tinymce-formats.css` and adds the CSS classes defined in those files to TinyMCE's {menuselection}`Format --> Formats` menu by using the [`importcss_file_filter` option](https://www.tiny.cloud/docs/tinymce/latest/importcss/#importcss_file_filter).

To add custom formats, you can provide your own files.

1. Name the file {file}`tinymce-formats.css`.
1. Register the file as a resource in your Plone site.
1. Include the file in the TinyMCE control panel in the textarea input {guilabel}`Choose the CSS used in WYSIWYG Editor Area`.
1. Navigate to {menuselection}`Site Setup --> TinyMCE --> Default`, or append `@@tinymce-controlpanel` to the root of your website in your browser's location bar.
1. Scroll down to {guilabel}`Choose the CSS used in WYSIWYG Editor Area`.

CSS styles defined in this file will automatically be added to the top level of TinyMCE's {menuselection}`Format --> Formats` menu.


## Remove imported formats
stevepiercy marked this conversation as resolved.
Show resolved Hide resolved

Plone 6 Classic UI ships with the Barceloneta theme which includes two custom formats, `highlight-inline` and `p.highlight-paragraph`, in the TinyMCE {menuselection}`Format --> Formats` menu.
You can remove these formats through the TinyMCE control panel.

1. Navigate to {menuselection}`Site Setup --> TinyMCE --> Default`, or append `@@tinymce-controlpanel` to the root of your website in your browser's location bar.
1. Scroll down to {guilabel}`Choose the CSS used in WYSIWYG Editor Area`.
1. Remove the entry `++theme++barceloneta/tinymce/tinymce-formats.css`.
1. Click the {guilabel}`Save` button.

Once removed, the custom formats will no longer appear in the menu.
Loading