Skip to content

Commit

Permalink
Add superscript capability to RichTextField (for AP mostly) (#557)
Browse files Browse the repository at this point in the history
* Add superscript capability to RichTextField (for AP mostly)

* Add superscript as default to editor
  • Loading branch information
mwvolo authored and RoyEJohnson committed Mar 15, 2018
1 parent 2b7d463 commit a1cfec9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
31 changes: 31 additions & 0 deletions global_settings/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import wagtail.admin.rich_text.editors.draftail.features as draftail_features
from wagtail.admin.rich_text.converters.html_to_contentstate import InlineStyleElementHandler
from wagtail.core import hooks


@hooks.register('register_rich_text_features')
def register_strikethrough_feature(features):
"""
Registering the `superscript` feature, which uses the `SUPERSCRIPT` Draft.js inline style type,
and is stored as HTML with an `<sup>` tag.
"""
feature_name = 'superscript'
type_ = 'SUPERSCRIPT'
tag = 'sup'

control = {
'type': type_,
'label': '^',
'description': 'Superscript',
}

features.register_editor_plugin(
'draftail', feature_name, draftail_features.InlineStyleFeature(control)
)

db_conversion = {
'from_database_format': {tag: InlineStyleElementHandler(type_)},
'to_database_format': {'style_map': {type_: tag}},
}
features.default_features.append(feature_name)
features.register_converter_rule('contentstate', feature_name, db_conversion)
3 changes: 1 addition & 2 deletions news/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from django.db import models
from django import forms
from django.contrib.sites.shortcuts import get_current_site

from wagtail.core.models import Page
from wagtail.core.fields import RichTextField, StreamField
from wagtail.admin.edit_handlers import FieldPanel, PageChooserPanel, StreamFieldPanel
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.documents.edit_handlers import DocumentChooserPanel
from wagtail.embeds.blocks import EmbedBlock
Expand Down
2 changes: 1 addition & 1 deletion pages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ class Technology(Page):


class ErrataList(Page):
correction_schedule = RichTextField(features=['link', 'bold', 'italic', 'hr', 'ol', 'ul'])
correction_schedule = RichTextField()

api_fields = (
'correction_schedule',
Expand Down

0 comments on commit a1cfec9

Please sign in to comment.