0

Django Wagtail - Draftail - Multiple color highlighter

How do I use a RichTextEditor (draftail) in wagtail in order to mark different parts of the text with different styles?

The editor won't display the correct inline styling after saving the document.

There must be something wrong when wagtail reads the style from database.

1 Answers1

1

I had to solve a problem where we wanted to use highlighting feature in a rich text editor in wagtail and I thought i would share my solution since I couldn't find anything solving this problem online.

This solution allows you to highlight different parts of the text with 4 predefined colors.

The main part that solved it for me was

tag = f'span{feature_name}'

which uniquely could identify the correct spans in the editor.

https://gist.github.com/robodl/48dd4bece30fcaf56c785212931f3bcd

Result when using code with the css

Hopefully someone will find this useful!