Thursday, October 20, 2016¶
Coping with overrich HTML¶
We have a new model mixin
to automatically “bleach” the content of RichTextField even before
saving them to the database. This is to avoid problems like
#1239, which were possible after pasting text from certain MS
applications into a Lino RichTextField.
This mixin is now used by
(where #1239 occured).
I don’t yet dare to use it on the text fields in
lino_welfare.modlib.isip and children. Because it causes the
bleached fields to get permanently stripped of any tags that are not
allowed. And in case this would cause problems, users would report
them only when it is too late. For these fields we will need a kind of
special migration which keeps track of every change so that we can
eventually roll it back later.
But I do dare to use it on
lino_xl.lib.sales.models.ProductDocItem, which itself is
used in only one production site, and AFAIK they did not yet start to
use HTML descriptions.
One question was how to define the default value for this list of
allowed tags? Actually Lino already has such a list, it is in the
names field of
lino.utils.xmlgen.html.E. I slightly changed the API for
lino.utils.xmlgen.Namespace to make this data more
intuitive. Note that most other subpackages of
lino.utils.xmlgen are rather obsolete (except maybe
lino.modlib.comments.fixtures.demo fixture adds a few
comments which contain such hackerish HTML.