Exemplo n.º 1
0
def register_sansserif_feature(features):
    features.default_features.append('sansserif')
    """
    Registering the `sansserif` feature, which uses the `SANSSERIF` Draft.js entity type,
    and is stored as HTML with a `<span>` tag.
    """
    feature_name = 'sansserif'
    type_ = 'SANSSERIF'

    control = {
        'type': type_,
        'label': 'SS',
        'description': 'Sans Serif font',
    }

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

    features.register_converter_rule(
        'contentstate',
        feature_name,
        {
            # Call register_converter_rule to register the content transformation conversion
            'from_database_format': {
                'span': sansserif.SansserifEntityElementHandler(type_)
            },
            'to_database_format': {
                'entity_decorators': {
                    type_: sansserif.sansserif_entity_decorator
                }
            },
        })
Exemplo n.º 2
0
def register_document_feature(features):
    features.register_link_type('document', document_linktype_handler)

    features.register_editor_plugin(
        'hallo', 'document-link',
        HalloPlugin(
            name='hallowagtaildoclink',
            js=['wagtaildocs/js/hallo-plugins/hallo-wagtaildoclink.js'],
        ))
    features.register_editor_plugin(
        'draftail', 'document-link',
        draftail_features.EntityFeature({
            'type': 'DOCUMENT',
            'icon': 'doc-full',
            'description': ugettext('Document'),
            'source': 'ModalWorkflowSource',
            'decorator': 'Document',
        }))

    features.register_converter_rule('editorhtml', 'document-link',
                                     EditorHTMLDocumentLinkConversionRule)
    features.register_converter_rule('contentstate', 'document-link',
                                     ContentstateDocumentLinkConversionRule)

    features.default_features.append('document-link')
Exemplo n.º 3
0
def register_embed_feature(features):
    # define a handler for converting <embed embedtype="media"> tags into frontend HTML
    features.register_embed_type(MediaEmbedHandler)

    # define how to convert between editorhtml's representation of embeds and
    # the database representation
    features.register_converter_rule(
        "editorhtml", "embed", EditorHTMLEmbedConversionRule
    )

    # define a draftail plugin to use when the 'embed' feature is active
    features.register_editor_plugin(
        "draftail",
        "embed",
        draftail_features.EntityFeature(
            {
                "type": "EMBED",
                "icon": "media",
                "description": _("Embed"),
            },
            js=["wagtailembeds/js/embed-chooser-modal.js"],
        ),
    )

    # define how to convert between contentstate's representation of embeds and
    # the database representation-
    features.register_converter_rule(
        "contentstate", "embed", ContentstateMediaConversionRule
    )

    # add 'embed' to the set of on-by-default rich text features
    features.default_features.append("embed")
Exemplo n.º 4
0
def register_embed_feature(features):
    # define a handler for converting <embed embedtype="media"> tags into frontend HTML
    features.register_embed_type(MediaEmbedHandler)

    # define a hallo.js plugin to use when the 'embed' feature is active
    features.register_editor_plugin(
        'hallo', 'embed',
        HalloPlugin(
            name='hallowagtailembeds',
            js=[
                'wagtailembeds/js/embed-chooser-modal.js',
                'wagtailembeds/js/hallo-plugins/hallo-wagtailembeds.js',
            ],
        )
    )

    # define how to convert between editorhtml's representation of embeds and
    # the database representation
    features.register_converter_rule('editorhtml', 'embed', EditorHTMLEmbedConversionRule)

    # define a draftail plugin to use when the 'embed' feature is active
    features.register_editor_plugin(
        'draftail', 'embed', draftail_features.EntityFeature({
            'type': 'EMBED',
            'icon': 'media',
            'description': _('Embed'),
        }, js=['wagtailembeds/js/embed-chooser-modal.js'])
    )

    # define how to convert between contentstate's representation of embeds and
    # the database representation-
    features.register_converter_rule('contentstate', 'embed', ContentstateMediaConversionRule)

    # add 'embed' to the set of on-by-default rich text features
    features.default_features.append('embed')
Exemplo n.º 5
0
def register_stock_feature(features):
    features.default_features.append('typograf')

    feature_name = 'typograf'
    type_ = 'TYPOGRAF'

    control = {
        'type': type_,
        'label': 'TF',
        'description': 'Типографировать текст',
    }

    features.register_editor_plugin(
        'draftail', feature_name,
        draftail_features.EntityFeature(
            control,
            js=[
                'wagtail-richtext-typograf/js/typograf.all.min.js',
                'wagtail-richtext-typograf/js/richtext.typograf.js'
            ]))

    features.register_converter_rule(
        'contentstate', feature_name, {
            'from_database_format': {
                'span[data-typograf]': TypografEntityElementHandler(type_)
            },
            'to_database_format': {
                'entity_decorators': {
                    type_: typograf_entity_decorator
                }
            },
        })
Exemplo n.º 6
0
def register_toc_feature(features):
    features.default_features.append('toc')
    """
    Registering the `toc` feature, which uses the `TOCHEADING` Draft.js entity type,
    and is stored as HTML with a `<h2 id>` tag.
    """
    feature_name = 'toc'
    type_ = 'TOCHEADING'

    control = {
        'type': type_,
        'label': '#',
        'description': 'TOC Heading',
    }

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

    features.register_converter_rule(
        'contentstate',
        feature_name,
        {
            # Note here that the conversion is more complicated than for blocks and inline styles.
            'from_database_format': {
                'h2[id]': TocEntityElementHandler(type_)
            },
            'to_database_format': {
                'entity_decorators': {
                    type_: toc_entity_decorator
                }
            },
        })
Exemplo n.º 7
0
def register_tip_feature(features):
    features.default_features.append('tip')
    """
    Registering the `tip` feature, which uses the `tip` Draft.js entity type,
    and is stored as HTML with a `<span data-tip>` tag.
    """
    feature_name = 'tip'
    type_ = 'TIP'

    control = {
        'type': type_,
        'label': 'ⓘ',
        'description': 'Tip',
    }

    features.register_editor_plugin(
        'draftail', feature_name,
        draftail_features.EntityFeature(control,
                                        js=['js/tip.js'],
                                        css={'all': ['css/tip.css']}))

    features.register_converter_rule(
        'contentstate',
        feature_name,
        {
            # Note here that the conversion is more complicated than for blocks and inline styles.
            'from_database_format': {
                'span[data-tip]': TipEntityElementHandler(type_)
            },
            'to_database_format': {
                'entity_decorators': {
                    type_: tip_entity_decorator
                }
            },
        })
Exemplo n.º 8
0
def register_snippet_embed_feature(features):
    feature_name = "snippet-embed"
    type_ = "SNIPPET-EMBED"

    features.register_embed_type(SnippetEmbedHandler)

    features.register_editor_plugin(
        "draftail",
        feature_name,
        draftail_features.EntityFeature(
            {
                "type": type_,
                "icon": "code",
                "description": ugettext("Snippet Embed")
            },
            js=[
                "wagtailsnippets/js/snippet-chooser-modal.js",
                "wagtail_draftail_snippet/js/snippet-model-chooser-modal.js",
                "wagtail_draftail_snippet/js/wagtail-draftail-snippet.js",
            ],
        ),
    )

    features.register_converter_rule("contentstate", feature_name,
                                     ContentstateSnippetEmbedConversionRule)
Exemplo n.º 9
0
def register_document_feature(features):
    features.register_link_type(DocumentLinkHandler)

    features.register_editor_plugin(
        'hallo', 'document-link',
        HalloPlugin(
            name='hallowagtaildoclink',
            js=[
                'wagtaildocs/js/document-chooser-modal.js',
                'wagtaildocs/js/hallo-plugins/hallo-wagtaildoclink.js',
            ],
        ))
    features.register_editor_plugin(
        'draftail', 'document-link',
        draftail_features.EntityFeature(
            {
                'type': 'DOCUMENT',
                'icon': 'doc-full',
                'description': gettext('Document'),
            },
            js=['wagtaildocs/js/document-chooser-modal.js']))

    features.register_converter_rule('editorhtml', 'document-link',
                                     EditorHTMLDocumentLinkConversionRule)
    features.register_converter_rule('contentstate', 'document-link',
                                     ContentstateDocumentLinkConversionRule)

    features.default_features.append('document-link')
Exemplo n.º 10
0
def register_rich_text_anchor_feature(features):
    features.default_features.append('anchor')
    """
    Registering the `anchor` feature, which uses the
    `ANCHOR` Draft.js entity type,
    and is stored as HTML with a `<a data-anchor href="#my-anchor">` tag.
    """
    feature_name = 'anchor'
    type_ = 'ANCHOR'

    control = {
        'type': type_,
        'label': '#',
        'description': 'Internal Link',
    }

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

    features.register_converter_rule(
        'contentstate',
        feature_name,
        {
            # Note here that the conversion is more
            # complicated than for blocks and inline styles.
            'from_database_format': {
                'a[data-anchor]': AnchorEntityElementHandler(type_)
            },
            'to_database_format': {
                'entity_decorators': {
                    type_: anchor_entity_decorator
                }
            },
        })
Exemplo n.º 11
0
def register_textcolour_feature(features):
    # register all colour features
    register_all_colour_features(features)

    # register the color picker
    feature_name = 'textcolour'
    type_ = feature_name.upper()

    control = {
        'type': type_,
        'icon': get_setting('ICON'),
        'description': _('Text Colour'),
    }

    features.register_editor_plugin(
        'draftail', feature_name,
        draftail_features.EntityFeature(
            control,
            js=[
                'colourpicker/js/chooser.js',
                'colourpicker/js/colourpicker.js',
            ],
            css={
                'all': ['colourpicker/css/colourpicker.css'],
            }))

    features.default_features.append(feature_name)
Exemplo n.º 12
0
def register_extended_link_feature(features):
    features.default_features.append('extended_link')
    feature_name = 'extended_link'
    type_ = 'LINK'

    control = {
        'type': type_,
        'label': 'Ex',
        'icon': 'icon icon-pick',
        'description': 'External Source Link',
        'attributes': ['url', 'id', 'parentId', 'rel', 'target', 'class'],
        'whitelist': {
            'href': "^(http:|https:|undefined$)",
        }
    }

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

    features.register_converter_rule(
        'contentstate', feature_name, {
            'from_database_format': {
                'a[href]': ExternalLinkElementHandler('LINK'),
                'a[linktype="page"]': PageLinkElementHandler('LINK'),
            },
            'to_database_format': {
                'entity_decorators': {
                    'LINK': extended_link_entity
                }
            }
        })
Exemplo n.º 13
0
def register_rich_text_anchor_identifier_feature(features):
    features.default_features.append('anchor-identifier')
    """
    Registering the `anchor-identifier` feature, which uses the
    `ANCHOR-IDENTIFIER` Draft.js entity type,
    and is stored as HTML with a `<a data-anchor href="#my-anchor"
    id="my-anchor">` tag.
    """
    feature_name = 'anchor-identifier'
    type_ = 'ANCHOR-IDENTIFIER'

    control = {
        'type': type_,
        'icon': 'icon icon-tag',
        'label': '',
        'description': 'Add Bookmark',
    }

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

    features.register_converter_rule(
        'contentstate', feature_name, {
            'from_database_format': {
                'a[data-id]': AnchorIndentifierEntityElementHandler(type_)
            },
            'to_database_format': {
                'entity_decorators': {
                    type_: anchor_identifier_entity_decorator
                }
            },
        })
Exemplo n.º 14
0
def register_footnotes_feature(features):
    """
    Registering the `footnotes` feature, which uses the `FOOTNOTES` Draft.js
    entity type, and is stored as HTML with a
    `<footnotes id="">short-id</footnotes>` tag.
    """
    feature_name = "footnotes"
    type_ = "FOOTNOTES"

    control = {"type": type_, "label": "Fn", "description": "Footnotes"}

    features.register_editor_plugin(
        "draftail",
        feature_name,
        draftail_features.EntityFeature(
            control,
            js=['wagtailadmin/js/draftail.js', 'footnotes/js/footnotes.js']),
    )

    features.register_converter_rule(
        "contentstate",
        feature_name,
        {
            "from_database_format": {
                "footnote[id]": FootnotesEntityElementHandler(type_)
            },
            "to_database_format": {
                "entity_decorators": {
                    type_: footnotes_entity_decorator
                }
            },
        },
    )
Exemplo n.º 15
0
def register_katex_feature(features):
    feature_name = 'katex'
    type_ = 'KATEX'

    control = {
        'type': type_,
        'label': '𝐊',
        'description': 'KaTeX',
    }

    features.register_editor_plugin(
        'draftail', feature_name,
        draftail_features.EntityFeature(
            control,
            js=[
                static('js/katex.min.js'),
                static('js/wagtail_draftail_katex.js'),
            ],
            css={'all': [static('css/katex.min.css')]}))

    db_conversion = {
        'from_database_format': {
            'div[data-katex-text]': KaTeXEntityElementHandler()
        },
        'to_database_format': {
            'entity_decorators': {
                type_: katex_entity_decorator
            }
        },
    }

    features.default_features.append(feature_name)
    features.register_converter_rule('contentstate', feature_name,
                                     db_conversion)
Exemplo n.º 16
0
def register_anchor_feature(features):
    """Register the `anchor` feature, which uses the `ANCHOR` Draft.js entity type, and is stored as HTML with a `<a href>` tag."""
    features.default_features.append('anchor')
    feature_name = 'anchor'
    type_ = 'ANCHOR'

    control = {
        'type': type_,
        'icon': 'order-down',
        'description': 'Skip link',
    }

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

    features.register_converter_rule(
        'contentstate', feature_name, {
            'from_database_format': {
                'a[href]': AnchorEntityElementHandler(type_)
            },
            'to_database_format': {
                'entity_decorators': {
                    type_: anchor_entity_decorator
                }
            },
        })
Exemplo n.º 17
0
def register_custom_media_feature(features):
    # Register a handler for converting <embed type="customimage"> to frontend HTML
    if WAGTAIL_VERSION < (2, 5):
        features.register_embed_type(embed_type='media',
                                     handler=MediaEmbedHandler)
    else:
        features.register_embed_type(MediaEmbedHandler)

    feature_name = 'wagtailmedia'

    control = {
        'type': 'MEDIA',
        'icon': 'media',
        'description': 'Media',
    }

    plugin_js = [
        'wagtailmedia/js/media-chooser-modal.js',
        'wagtailmedia/js/WagtailMediaBlock.js',
    ]

    features.register_editor_plugin(
        'draftail', feature_name,
        draftail_features.EntityFeature(control, js=plugin_js))

    features.register_converter_rule('contentstate', feature_name,
                                     ContentstateMediaConversionRule)

    features.default_features.append(feature_name)
Exemplo n.º 18
0
def register_footnote_feature(features):
    features.default_features.append('footnote')
    """
    Registering the `footnote` feature, which uses the `FOOTNOTE` Draft.js entity type,
    and is stored as HTML with a `<span data-footnote>` tag.
    """
    feature_name = 'footnote'
    type_ = 'FOOTNOTE'

    control = {
        'type': type_,
        'icon': ICON_PATH,
        'description': 'Footnote',
    }

    features.register_editor_plugin(
        'draftail', feature_name, draftail_features.EntityFeature(
            control,
            js=['footnotes/js/custom-admin.js'],
            css={'all': ['footnotes/css/footnotes.css']}
        )
    )

    features.register_converter_rule('contentstate', feature_name, {
        # Note here that the conversion is more complicated than for blocks and inline styles.
        'from_database_format': {'span[data-footnote]': FootnoteEntityElementHandler(type_)},
        'to_database_format': {'entity_decorators': {type_: footnote_entity_decorator}},
    })
def register_rich_text_features(features):
    features.default_features.append('katex')
    """
    Registering the `katex` feature, which uses the `KATEX` Draft.js entity type,
    and is stored as HTML with a `<div data-katex-text="c = \\pm\\sqrt{a^2 + b^2}">` tag.
    """
    feature_name = 'katex'
    type_ = 'KATEX'

    control = {
        'type': type_,
        'label': '𝐊',
        'description': 'KaTeX',
    }

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

    features.register_converter_rule(
        'contentstate',
        feature_name,
        {
            # Note here that the conversion is more complicated than for blocks and inline styles.
            'from_database_format': {
                'div[data-katex-text]': KaTeXEntityElementHandler()
            },
            'to_database_format': {
                'entity_decorators': {
                    type_: katex_entity_decorator
                }
            },
        })
Exemplo n.º 20
0
def register_glossary_feature(features):
    features.default_features.append('glossary')
    """
    Registering the `glossary` feature, which uses the `GLOSSARY` Draft.js entity type,
    and is stored as HTML with a `<span data-term>` tag.
    """
    feature_name = 'glossary'
    type_ = 'GLOSSARY'

    control = {
        'type': type_,
        'label': 'Glossary',
        'description': 'Glossary',
    }

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

    features.register_converter_rule(
        'contentstate',
        feature_name,
        {
            # Call register_converter_rule to register the content transformation conversion
            'from_database_format': {
                'span[data-term]': glossary.GlossaryEntityElementHandler(type_)
            },
            'to_database_format': {
                'entity_decorators': {
                    type_: glossary.glossary_entity_decorator
                }
            },
        })
Exemplo n.º 21
0
def register_rich_text_features(features):
    features.default_features.append('katex')
    """
    Registering the `katex` feature, which uses the `KATEX` Draft.js entity type,
    and is stored as HTML with a `<div data-katex-text="c = \\pm\\sqrt{a^2 + b^2}">` tag.
    """
    feature_name = 'katex'
    type_ = 'KATEX'

    control = {
        'type': type_,
        'label': '𝐊',
        'description': 'KaTeX',
    }

    if WAGTAIL_VERSION >= (2, 2):
        features.register_editor_plugin(
            'draftail', feature_name,
            draftail_features.EntityFeature(
                control,
                js=[
                    '{}draftail_katex/js/katex.min.js'.format(
                        settings.STATIC_URL),
                    '{}draftail_katex/js/wagtail_draftail_katex.js'.format(
                        settings.STATIC_URL),
                ],
                css={
                    'all': [
                        '{}draftail_katex/css/katex.min.css'.format(
                            settings.STATIC_URL),
                    ]
                }))
    else:
        features.register_editor_plugin(
            'draftail', feature_name, draftail_features.EntityFeature(control))

    features.register_converter_rule(
        'contentstate', feature_name, {
            'from_database_format': {
                'div[data-katex-text]': KaTeXEntityElementHandler()
            },
            'to_database_format': {
                'entity_decorators': {
                    type_: katex_entity_decorator
                }
            },
        })
Exemplo n.º 22
0
def register_quotation_feature(features):
    features.register_editor_plugin(
        "draftail",
        "quotation",
        draftail_features.EntityFeature(
            {},
            js=["testapp/js/draftail-quotation.js"],
            css={"all": ["testapp/css/draftail-quotation.css"]},
        ),
    )
Exemplo n.º 23
0
def register_image_feature(features):
    # define a handler for converting <embed embedtype="image"> tags into frontend HTML
    features.register_embed_type(ImageEmbedHandler)

    # define a hallo.js plugin to use when the 'image' feature is active
    features.register_editor_plugin(
        'hallo', 'image',
        HalloPlugin(
            name='hallowagtailimage',
            js=[
                versioned_static('wagtailimages/js/image-chooser-modal.js'),
                versioned_static(
                    'wagtailimages/js/hallo-plugins/hallo-wagtailimage.js'),
            ],
        ))

    # define how to convert between editorhtml's representation of images and
    # the database representation
    features.register_converter_rule('editorhtml', 'image',
                                     EditorHTMLImageConversionRule)

    # define a draftail plugin to use when the 'image' feature is active
    features.register_editor_plugin(
        'draftail',
        'image',
        draftail_features.EntityFeature(
            {
                'type': 'IMAGE',
                'icon': 'image',
                'description': ugettext('Image'),
                # We do not want users to be able to copy-paste hotlinked images into rich text.
                # Keep only the attributes Wagtail needs.
                'attributes': ['id', 'src', 'alt', 'format'],
                # Keep only images which are from Wagtail.
                'whitelist': {
                    'id': True,
                }
            },
            js=[
                versioned_static('wagtailimages/js/image-chooser-modal.js'),
            ]))

    # define how to convert between contentstate's representation of images and
    # the database representation
    features.register_converter_rule('contentstate', 'image',
                                     ContentstateImageConversionRule)

    # add 'image' to the set of on-by-default rich text features
    features.default_features.append('image')
Exemplo n.º 24
0
def register_blockquote_feature(features):
    features.register_editor_plugin(
        'hallo', 'blockquote',
        HalloPlugin(
            name='halloblockquote',
            js=['testapp/js/hallo-blockquote.js'],
            css={'all': ['testapp/css/hallo-blockquote.css']},
        ))
    features.register_editor_plugin(
        'draftail', 'blockquote',
        draftail_features.EntityFeature(
            {},
            js=['testapp/js/draftail-blockquote.js'],
            css={'all': ['testapp/css/draftail-blockquote.css']},
        ))
Exemplo n.º 25
0
def register_quotation_feature(features):
    features.register_editor_plugin(
        'hallo', 'quotation',
        HalloPlugin(
            name='halloquotation',
            js=['testapp/js/hallo-quotation.js'],
            css={'all': ['testapp/css/hallo-quotation.css']},
        ))
    features.register_editor_plugin(
        'draftail', 'quotation',
        draftail_features.EntityFeature(
            {},
            js=['testapp/js/draftail-quotation.js'],
            css={'all': ['testapp/css/draftail-quotation.css']},
        ))
def register_textsize_feature(features):
    # register all font size features
    register_all_font_size_features(features)

    # register the font size picker
    feature_name = 'textsize'
    type_ = feature_name.upper()

    control = {
        'type': type_,
        'icon': 'arrows-up-down',
        'description': _('Text Colour'),
    }

    features.register_editor_plugin(
        'draftail', feature_name,
        draftail_features.EntityFeature(control,
                                        js=['colourpicker/js/chooser.js']))

    features.default_features.append(feature_name)
Exemplo n.º 27
0
def register_image_feature(features):
    # define a handler for converting <embed embedtype="image"> tags into frontend HTML
    features.register_embed_type(ImageEmbedHandler)

    # define how to convert between editorhtml's representation of images and
    # the database representation
    features.register_converter_rule(
        "editorhtml", "image", EditorHTMLImageConversionRule
    )

    # define a draftail plugin to use when the 'image' feature is active
    features.register_editor_plugin(
        "draftail",
        "image",
        draftail_features.EntityFeature(
            {
                "type": "IMAGE",
                "icon": "image",
                "description": gettext("Image"),
                # We do not want users to be able to copy-paste hotlinked images into rich text.
                # Keep only the attributes Wagtail needs.
                "attributes": ["id", "src", "alt", "format"],
                # Keep only images which are from Wagtail.
                "allowlist": {
                    "id": True,
                },
            },
            js=[
                "wagtailimages/js/image-chooser-modal.js",
            ],
        ),
    )

    # define how to convert between contentstate's representation of images and
    # the database representation
    features.register_converter_rule(
        "contentstate", "image", ContentstateImageConversionRule
    )

    # add 'image' to the set of on-by-default rich text features
    features.default_features.append("image")
def register_anchorid_features(features):
    features.default_features.append('anchorid')
    feature_name = 'anchorid'
    type_ = 'ANCHORID'

    control = {'type': type_, 'label': '<id>', 'description': 'ID attribute'}

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

    features.register_converter_rule(
        'contentstate', feature_name, {
            'from_database_format': {
                'span': AnchorIDEntityElementHandler(type_)
            },
            'to_database_format': {
                'entity_decorators': {
                    type_: anchorid_entity_decorator
                }
            },
        })
Exemplo n.º 29
0
def register_document_feature(features):
    features.register_link_type(DocumentLinkHandler)

    features.register_editor_plugin(
        "draftail",
        "document-link",
        draftail_features.EntityFeature(
            {
                "type": "DOCUMENT",
                "icon": "doc-full",
                "description": gettext("Document"),
            },
            js=["wagtaildocs/js/document-chooser-modal.js"],
        ),
    )

    features.register_converter_rule("editorhtml", "document-link",
                                     EditorHTMLDocumentLinkConversionRule)
    features.register_converter_rule("contentstate", "document-link",
                                     ContentstateDocumentLinkConversionRule)

    features.default_features.append("document-link")
Exemplo n.º 30
0
def register_rich_text_colour_feature(features):
    features.default_features.append('colour')
    """
    Registering the `anchor` feature, which uses the
    `ANCHOR` Draft.js entity type,
    and is stored as HTML with a `<a data-anchor href="#my-anchor">` tag.
    """
    feature_name = 'colour'
    type_ = 'COLOUR'

    control = {
        'type': type_,
        # Yeah I know, but wagtail provide such a limited set of options!
        'icon': 'icon icon-radio-full',
        'label': '',
        'description': 'Font Colour',
    }

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

    features.register_converter_rule(
        'contentstate',
        feature_name,
        {
            # Note here that the conversion is more
            # complicated than for blocks and inline styles.
            'from_database_format': {
                'span[data-color]': ColourEntityElementHandler(type_)
            },
            'to_database_format': {
                'entity_decorators': {
                    type_: colour_entity_decorator
                }
            },
        })