Ensure order of headings features is consistent for HalloJS

pull/4398/merge
Loic Teixeira 2018-04-04 13:35:11 +10:00
rodzic 724262130c
commit b12a7b08bd
5 zmienionych plików z 32 dodań i 3 usunięć

Wyświetl plik

@ -38,6 +38,7 @@ Changelog
* Fix: Localization of image and apps verbose names
* Fix: Draftail editor no longer crashes after deleting image/embed using DEL key (Thibaud Colas)
* Fix: Breadcrumb navigation now respects custom `get_admin_display_title` methods (Arthur Holzner, Wietze Helmantel, Matt Westcott)
* Fix: Inconsistent order of heading features when adding h1, h5 or h6 as default feature for Hallo RichText editor (Loic Teixeira)
2.0.1 (04.04.2018)

Wyświetl plik

@ -56,6 +56,7 @@ Bug fixes
* Localization of image and apps verbose names
* Draftail editor no longer crashes after deleting image/embed using DEL key (Thibaud Colas)
* Breadcrumb navigation now respects custom ``get_admin_display_title`` methods (Arthur Holzner, Wietze Helmantel, Matt Westcott)
* Inconsistent order of heading features when adding h1, h5 or h6 as default feature for Hallo RichText editor (Loic Teixeira)
Upgrade considerations

Wyświetl plik

@ -41,9 +41,11 @@ class HalloFormatPlugin(HalloPlugin):
class HalloHeadingPlugin(HalloPlugin):
default_order = 20
def __init__(self, **kwargs):
kwargs.setdefault('name', 'halloheadings')
kwargs.setdefault('order', 20)
kwargs.setdefault('order', self.default_order)
self.element = kwargs.pop('element')
super().__init__(**kwargs)

Wyświetl plik

@ -8,6 +8,7 @@ from wagtail.admin.rich_text import (
DraftailRichTextArea, HalloRichTextArea, get_rich_text_editor_widget)
from wagtail.core.blocks import RichTextBlock
from wagtail.core.models import Page, get_page_models
from wagtail.core.rich_text import features as feature_registry
from wagtail.core.rich_text import RichText
from wagtail.tests.testapp.models import SingleEventPage
from wagtail.tests.testapp.rich_text import CustomRichTextArea
@ -504,6 +505,28 @@ class TestHalloJsWithCustomFeatureOptions(BaseRichTextEditHandlerTestCase, Wagta
self.assertNotIn('wagtaildocs/js/hallo-plugins/hallo-wagtaildoclink.js', media_html)
@override_settings(WAGTAILADMIN_RICH_TEXT_EDITORS={
'default': {
'WIDGET': 'wagtail.admin.rich_text.HalloRichTextArea'
},
})
class TestHalloJsHeadingOrder(BaseRichTextEditHandlerTestCase, WagtailTestUtils):
def test_heading_order(self):
# Using the `register_rich_text_features` doesn't work here,
# probably because the features have already been scanned at that point.
# Extending the registry directly instead.
feature_registry.default_features.extend(['h1', 'h5', 'h6'])
widget = HalloRichTextArea()
js_init = widget.render_js_init('the_id', 'the_name', '<p>the value</p>')
expected_options = (
'"halloheadings": {"formatBlocks": ["p", "h1", "h2", "h3", "h4", "h5", "h6"]}'
)
self.assertIn(expected_options, js_init)
class TestWidgetWhitelisting(TestCase, WagtailTestUtils):
def test_default_whitelist(self):
widget = HalloRichTextArea()

Wyświetl plik

@ -287,9 +287,11 @@ def register_core_features(features):
WhitelistRule('em', allow_without_attributes),
])
for element in ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']:
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)
'hallo', element, HalloHeadingPlugin(element=element, order=order)
)
features.register_converter_rule('editorhtml', element, [
WhitelistRule(element, allow_without_attributes)