示例#1
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')
示例#2
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')
示例#3
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')
示例#4
0
def register_embed_feature(features):
    features.register_editor_plugin(
        'hallo', 'document-link',
        HalloPlugin(
            name='hallowagtaildoclink',
            js=['wagtaildocs/js/hallo-plugins/hallo-wagtaildoclink.js'],
        ))
    features.default_features.append('document-link')
示例#5
0
def register_embed_feature(features):
    features.register_editor_plugin(
        'hallo', 'embed',
        HalloPlugin(
            name='hallowagtailembeds',
            js=['wagtailembeds/js/hallo-plugins/hallo-wagtailembeds.js'],
        ))
    features.default_features.append('embed')
示例#6
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']},
        ))
示例#7
0
def register_html_feature(features):
    features.register_editor_plugin(
        'hallo', 'edit-html',
        HalloPlugin(
            name='editHtmlButton',
            js=['js/html_editor.js'],
        )
    )
示例#8
0
def register_tips_feature(features):
    features.register_editor_plugin(
        'hallo', 'ask-tips',
        HalloPlugin(
            name='answermodule',
            js=['js/ask_cfpb_tips.js'],
        )
    )
示例#9
0
def register_image_feature(features):
    features.register_editor_plugin(
        'hallo', 'image',
        HalloPlugin(
            name='hallowagtailimage',
            js=['wagtailimages/js/hallo-plugins/hallo-wagtailimage.js'],
        )
    )
    features.default_features.append('image')
示例#10
0
def register_embed_feature(features):
    features.register_editor_plugin(
        'hallo', 'snippet',
        HalloPlugin(
            name='hallowagtailsnippetlink',
            js=['snippet_linker/js/hallo-plugins/hallo-wagtailsnippetlink.js'],
        ))
    features.default_features.append('snippet')
    features.default_features.append('h5')
示例#11
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_converter_rule('editorhtml', 'document-link', [
        LinkTypeRule('document', DocumentLinkHandler),
    ])
    features.default_features.append('document-link')
示例#12
0
def register_core_features(features):
    features.register_editor_plugin(
        'hallo', 'hr',
        HalloPlugin(
            name='hallohr',
            js=['wagtailadmin/js/hallo-plugins/hallo-hr.js'],
            order=45,
        ))
    features.default_features.append('hr')

    features.register_editor_plugin(
        'hallo', 'link',
        HalloPlugin(
            name='hallowagtaillink',
            js=['wagtailadmin/js/hallo-plugins/hallo-wagtaillink.js'],
        ))
    features.default_features.append('link')

    features.register_editor_plugin('hallo', 'bold',
                                    HalloFormatPlugin(format_name='bold'))
    features.default_features.append('bold')

    features.register_editor_plugin('hallo', 'italic',
                                    HalloFormatPlugin(format_name='italic'))
    features.default_features.append('italic')

    for element in ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']:
        features.register_editor_plugin('hallo', element,
                                        HalloHeadingPlugin(element=element))
    features.default_features.extend(['h2', 'h3', 'h4'])

    features.register_editor_plugin('hallo', 'ol',
                                    HalloListPlugin(list_type='ordered'))
    features.default_features.append('ol')

    features.register_editor_plugin('hallo', 'ul',
                                    HalloListPlugin(list_type='unordered'))
    features.default_features.append('ul')
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')
示例#14
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']},
        ))
示例#15
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']},
        ))
示例#16
0
def register_embed_feature(features):
    # define a handler for converting <embed embedtype="media"> tags into frontend HTML
    features.register_embed_type('media', media_embedtype_handler)

    # 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/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', [EmbedTypeRule('media', MediaEmbedHandler)])

    # add 'embed' to the set of on-by-default rich text features
    features.default_features.append('embed')
示例#17
0
def register_core_features(features):
    # Hallo.js
    features.register_editor_plugin(
        'hallo', 'hr',
        HalloPlugin(
            name='hallohr',
            js=[versioned_static('wagtailadmin/js/hallo-plugins/hallo-hr.js')],
            order=45,
        ))
    features.register_converter_rule(
        'editorhtml', 'hr', [WhitelistRule('hr', allow_without_attributes)])

    features.register_editor_plugin(
        'hallo', 'link',
        HalloPlugin(
            name='hallowagtaillink',
            js=[
                versioned_static('wagtailadmin/js/page-chooser-modal.js'),
                versioned_static(
                    'wagtailadmin/js/hallo-plugins/hallo-wagtaillink.js'),
            ],
        ))
    features.register_converter_rule('editorhtml', 'link', [
        WhitelistRule('a', attribute_rule({'href': check_url})),
        LinkTypeRule('page', PageLinkHandler),
    ])

    features.register_editor_plugin('hallo', 'bold',
                                    HalloFormatPlugin(format_name='bold'))
    features.register_converter_rule('editorhtml', 'bold', [
        WhitelistRule('b', allow_without_attributes),
        WhitelistRule('strong', allow_without_attributes),
    ])

    features.register_editor_plugin('hallo', 'italic',
                                    HalloFormatPlugin(format_name='italic'))
    features.register_converter_rule('editorhtml', 'italic', [
        WhitelistRule('i', allow_without_attributes),
        WhitelistRule('em', allow_without_attributes),
    ])

    headings_elements = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']
    headings_order_start = HalloHeadingPlugin.default_order + 1
    for order, element in enumerate(headings_elements,
                                    start=headings_order_start):
        features.register_editor_plugin(
            'hallo', element, HalloHeadingPlugin(element=element, order=order))
        features.register_converter_rule(
            'editorhtml', element,
            [WhitelistRule(element, allow_without_attributes)])

    features.register_editor_plugin('hallo', 'ol',
                                    HalloListPlugin(list_type='ordered'))
    features.register_converter_rule('editorhtml', 'ol', [
        WhitelistRule('ol', allow_without_attributes),
        WhitelistRule('li', allow_without_attributes),
    ])

    features.register_editor_plugin('hallo', 'ul',
                                    HalloListPlugin(list_type='unordered'))
    features.register_converter_rule('editorhtml', 'ul', [
        WhitelistRule('ul', allow_without_attributes),
        WhitelistRule('li', allow_without_attributes),
    ])

    # Draftail
    features.register_editor_plugin(
        'draftail', 'hr',
        draftail_features.BooleanFeature('enableHorizontalRule'))
    features.register_converter_rule(
        'contentstate', 'hr', {
            'from_database_format': {
                'hr': HorizontalRuleHandler(),
            },
            'to_database_format': {
                'entity_decorators': {
                    'HORIZONTAL_RULE': lambda props: DOM.create_element('hr')
                }
            }
        })

    features.register_editor_plugin(
        'draftail', 'h1',
        draftail_features.BlockFeature({
            'label':
            'H1',
            'type':
            'header-one',
            'description':
            ugettext('Heading {level}').format(level=1),
        }))
    features.register_converter_rule(
        'contentstate', 'h1', {
            'from_database_format': {
                'h1': BlockElementHandler('header-one'),
            },
            'to_database_format': {
                'block_map': {
                    'header-one': 'h1'
                }
            }
        })
    features.register_editor_plugin(
        'draftail', 'h2',
        draftail_features.BlockFeature({
            'label':
            'H2',
            'type':
            'header-two',
            'description':
            ugettext('Heading {level}').format(level=2),
        }))
    features.register_converter_rule(
        'contentstate', 'h2', {
            'from_database_format': {
                'h2': BlockElementHandler('header-two'),
            },
            'to_database_format': {
                'block_map': {
                    'header-two': 'h2'
                }
            }
        })
    features.register_editor_plugin(
        'draftail', 'h3',
        draftail_features.BlockFeature({
            'label':
            'H3',
            'type':
            'header-three',
            'description':
            ugettext('Heading {level}').format(level=3),
        }))
    features.register_converter_rule(
        'contentstate', 'h3', {
            'from_database_format': {
                'h3': BlockElementHandler('header-three'),
            },
            'to_database_format': {
                'block_map': {
                    'header-three': 'h3'
                }
            }
        })
    features.register_editor_plugin(
        'draftail', 'h4',
        draftail_features.BlockFeature({
            'label':
            'H4',
            'type':
            'header-four',
            'description':
            ugettext('Heading {level}').format(level=4),
        }))
    features.register_converter_rule(
        'contentstate', 'h4', {
            'from_database_format': {
                'h4': BlockElementHandler('header-four'),
            },
            'to_database_format': {
                'block_map': {
                    'header-four': 'h4'
                }
            }
        })
    features.register_editor_plugin(
        'draftail', 'h5',
        draftail_features.BlockFeature({
            'label':
            'H5',
            'type':
            'header-five',
            'description':
            ugettext('Heading {level}').format(level=5),
        }))
    features.register_converter_rule(
        'contentstate', 'h5', {
            'from_database_format': {
                'h5': BlockElementHandler('header-five'),
            },
            'to_database_format': {
                'block_map': {
                    'header-five': 'h5'
                }
            }
        })
    features.register_editor_plugin(
        'draftail', 'h6',
        draftail_features.BlockFeature({
            'label':
            'H6',
            'type':
            'header-six',
            'description':
            ugettext('Heading {level}').format(level=6),
        }))
    features.register_converter_rule(
        'contentstate', 'h6', {
            'from_database_format': {
                'h6': BlockElementHandler('header-six'),
            },
            'to_database_format': {
                'block_map': {
                    'header-six': 'h6'
                }
            }
        })
    features.register_editor_plugin(
        'draftail', 'ul',
        draftail_features.BlockFeature({
            'type':
            'unordered-list-item',
            'icon':
            'list-ul',
            'description':
            ugettext('Bulleted list'),
        }))
    features.register_converter_rule(
        'contentstate', 'ul', {
            'from_database_format': {
                'ul': ListElementHandler('unordered-list-item'),
                'li': ListItemElementHandler(),
            },
            'to_database_format': {
                'block_map': {
                    'unordered-list-item': {
                        'element': 'li',
                        'wrapper': 'ul'
                    }
                }
            }
        })
    features.register_editor_plugin(
        'draftail', 'ol',
        draftail_features.BlockFeature({
            'type':
            'ordered-list-item',
            'icon':
            'list-ol',
            'description':
            ugettext('Numbered list'),
        }))
    features.register_converter_rule(
        'contentstate', 'ol', {
            'from_database_format': {
                'ol': ListElementHandler('ordered-list-item'),
                'li': ListItemElementHandler(),
            },
            'to_database_format': {
                'block_map': {
                    'ordered-list-item': {
                        'element': 'li',
                        'wrapper': 'ol'
                    }
                }
            }
        })
    features.register_editor_plugin(
        'draftail', 'blockquote',
        draftail_features.BlockFeature({
            'type': 'blockquote',
            'icon': 'openquote',
            'description': ugettext('Blockquote'),
        }))
    features.register_converter_rule(
        'contentstate', 'blockquote', {
            'from_database_format': {
                'blockquote': BlockElementHandler('blockquote'),
            },
            'to_database_format': {
                'block_map': {
                    'blockquote': 'blockquote'
                }
            }
        })

    features.register_editor_plugin(
        'draftail', 'bold',
        draftail_features.InlineStyleFeature({
            'type': 'BOLD',
            'icon': 'bold',
            'description': ugettext('Bold'),
        }))
    features.register_converter_rule(
        'contentstate', 'bold', {
            'from_database_format': {
                'b': InlineStyleElementHandler('BOLD'),
                'strong': InlineStyleElementHandler('BOLD'),
            },
            'to_database_format': {
                'style_map': {
                    'BOLD': 'b'
                }
            }
        })
    features.register_editor_plugin(
        'draftail', 'italic',
        draftail_features.InlineStyleFeature({
            'type': 'ITALIC',
            'icon': 'italic',
            'description': ugettext('Italic'),
        }))
    features.register_converter_rule(
        'contentstate', 'italic', {
            'from_database_format': {
                'i': InlineStyleElementHandler('ITALIC'),
                'em': InlineStyleElementHandler('ITALIC'),
            },
            'to_database_format': {
                'style_map': {
                    'ITALIC': 'i'
                }
            }
        })

    features.register_editor_plugin(
        'draftail',
        'link',
        draftail_features.EntityFeature(
            {
                'type': 'LINK',
                'icon': 'link',
                'description': ugettext('Link'),
                # We want to enforce constraints on which links can be pasted into rich text.
                # Keep only the attributes Wagtail needs.
                'attributes': ['url', 'id', 'parentId'],
                'whitelist': {
                    # Keep pasted links with http/https protocol, and not-pasted links (href = undefined).
                    'href': "^(http:|https:|undefined$)",
                }
            },
            js=[
                versioned_static('wagtailadmin/js/page-chooser-modal.js'),
            ]))
    features.register_converter_rule(
        'contentstate', 'link', {
            'from_database_format': {
                'a[href]': ExternalLinkElementHandler('LINK'),
                'a[linktype="page"]': PageLinkElementHandler('LINK'),
            },
            'to_database_format': {
                'entity_decorators': {
                    'LINK': link_entity
                }
            }
        })
    features.register_editor_plugin(
        'draftail', 'superscript',
        draftail_features.InlineStyleFeature({
            'type':
            'SUPERSCRIPT',
            'icon':
            'superscript',
            'description':
            ugettext('Superscript'),
        }))
    features.register_converter_rule(
        'contentstate', 'superscript', {
            'from_database_format': {
                'sup': InlineStyleElementHandler('SUPERSCRIPT'),
            },
            'to_database_format': {
                'style_map': {
                    'SUPERSCRIPT': 'sup'
                }
            }
        })
    features.register_editor_plugin(
        'draftail', 'subscript',
        draftail_features.InlineStyleFeature({
            'type':
            'SUBSCRIPT',
            'icon':
            'subscript',
            'description':
            ugettext('Subscript'),
        }))
    features.register_converter_rule(
        'contentstate', 'subscript', {
            'from_database_format': {
                'sub': InlineStyleElementHandler('SUBSCRIPT'),
            },
            'to_database_format': {
                'style_map': {
                    'SUBSCRIPT': 'sub'
                }
            }
        })
    features.register_editor_plugin(
        'draftail', 'strikethrough',
        draftail_features.InlineStyleFeature({
            'type':
            'STRIKETHROUGH',
            'icon':
            'strikethrough',
            'description':
            ugettext('Strikethrough'),
        }))
    features.register_converter_rule(
        'contentstate', 'strikethrough', {
            'from_database_format': {
                's': InlineStyleElementHandler('STRIKETHROUGH'),
            },
            'to_database_format': {
                'style_map': {
                    'STRIKETHROUGH': 's'
                }
            }
        })
    features.register_editor_plugin(
        'draftail', 'code',
        draftail_features.InlineStyleFeature({
            'type': 'CODE',
            'icon': 'code',
            'description': ugettext('Code'),
        }))
    features.register_converter_rule(
        'contentstate', 'code', {
            'from_database_format': {
                'code': InlineStyleElementHandler('CODE'),
            },
            'to_database_format': {
                'style_map': {
                    'CODE': 'code'
                }
            }
        })