Skip to content

Commit

Permalink
Tinymce customization (#1807)
Browse files Browse the repository at this point in the history
* Create template for TinyMCE docs

* Migrate content from #1806

* Fix redirecting link to TinyMCE latest

* Update docs/classic-ui/tinymce-customization.md

Co-authored-by: Peter Mathis <petschki@users.noreply.github.com>

* Enhance tinymce customization documentation

* Explain each of the three options to better inform the reader's decision
Restructure the .css file option to be more how-to guide-ish

---------

Co-authored-by: Peter Mathis <petschki@users.noreply.github.com>
Co-authored-by: Peter Mathis <peter.mathis@kombinat.at>
  • Loading branch information
3 people authored Dec 5, 2024
1 parent 58bfcee commit 3eb6df2
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
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
<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

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.

0 comments on commit 3eb6df2

Please sign in to comment.