-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add superscript capability to RichTextField (for AP mostly) (#557)
* Add superscript capability to RichTextField (for AP mostly) * Add superscript as default to editor
- Loading branch information
1 parent
2b7d463
commit a1cfec9
Showing
3 changed files
with
33 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters