tinymce : Add the TinyMCE editor

The lino.modlib.tinymce plugin activates usage of the TinyMCE editor for HTML text fields (:class:lino.core.fields.RichTextField`) instead of the built-in Ext.form.HtmlEditor editor that comes with ExtJS.

A tested document

This is a tested document. The following instructions are used for initialization:

>>> from lino import startup
>>> startup('lino_book.projects.min9.settings.demo')
>>> from lino.api.doctest import *

Dependencies

This plugin makes sense only if lino.modlib.extjs is also installed. It also requires the lino.modlib.office plugin because it adds entries to the :menuselection`Office` menu.

>>> dd.plugins.tinymce.needs_plugins
['lino.modlib.office', 'lino.modlib.extjs']

Configuration

When serving static files from a different subdomain, TinyMCE needs to know about this.

Typical usage is to specify this in your lino_local.py file:

def setup_site(self):
    ...
    from lino.api.ad import configure_plugin
    configure_plugin('tinymce', document_domain="mydomain.com")

Currently when using this, you must also manually change your static tiny_mce_popup.js file after each collectstatic.

tiny_mce_popup.js

The factory version of that file contains:

// Uncomment and change this document.domain value if you are loading the script cross subdomains
// document.domain = 'moxiecode.com';

Uncomment and set the document.domain to the same value as your document_domain.

See lino.modlib.tinymce.Plugin

The Templates table

class lino.modlib.tinymce.TextFieldTemplate

A reusable block of text that can be selected from a text editor to be inserted into the text being edited.

class lino.modlib.tinymce.TextFieldTemplates
class lino.modlib.tinymce.MyTextFieldTemplates
class lino.modlib.tinymce.Templates

The Templates is designed to make usage of TinyMCE's external_template_list_url setting.

It is called by TinyMCE (template_external_list_url) to fill the list of available templates.

>>> url = "/tinymce/templates/notes/MyNotes/69/body"
>>> test_client.force_login(rt.login('robin').user)
>>> response = test_client.get(url, REMOTE_USER='robin')
>>> response.status_code
200
>>> print(response.content.decode())
... 
var tinyMCETemplateList = [
[ "hello", "/tinymce/templates/notes/MyNotes/69/body/1", "Inserts 'Hello, world!'" ],
[ "mfg", "/tinymce/templates/notes/MyNotes/69/body/2", "None" ]
];
>>> url = "/tinymce/templates/notes/MyNotes/69/body/1"
>>> response = test_client.get(url, REMOTE_USER='robin')
>>> response.status_code
200
>>> print(response.content.decode())
... 
<div>Hello, world!</div>