Don't insert a spacer paragraph when preceded by a list

pull/4319/head
Matt Westcott 2018-02-26 12:34:13 +00:00
rodzic 581e9a92c0
commit 3a638add7d
2 zmienionych plików z 37 dodań i 2 usunięć

Wyświetl plik

@ -28,6 +28,9 @@ class HandlerState:
# an atomic block which is NOT preceded by a non-atomic block must have a spacer
# paragraph inserted before it
# NB This is not included in pushed/popped state, because after a pop() this
# should still indicate the status of the most recent block, not the one preceding
# the corresponding push()
self.has_preceding_nonatomic_block = False
self.pushed_states = []
@ -40,7 +43,6 @@ class HandlerState:
'leading_whitespace': self.leading_whitespace,
'list_depth': self.list_depth,
'list_item_type': self.list_item_type,
'has_preceding_nonatomic_block': self.has_preceding_nonatomic_block,
})
def pop(self):
@ -51,7 +53,6 @@ class HandlerState:
self.leading_whitespace = last_state['leading_whitespace']
self.list_depth = last_state['list_depth']
self.list_item_type = last_state['list_item_type']
self.has_preceding_nonatomic_block = last_state['has_preceding_nonatomic_block']
def add_paragraph_block(state, contentstate):

Wyświetl plik

@ -432,6 +432,40 @@ class TestHtmlToContentState(TestCase):
}
})
def test_image_after_list(self):
"""
There should be no spacer paragraph inserted between a list and an image
"""
converter = ContentstateConverter(features=['ul', 'image'])
result = json.loads(converter.from_database_format(
'''
<ul>
<li>Milk</li>
<li>Eggs</li>
</ul>
<embed embedtype="image" alt="an image" id="1" format="left" />
<ul>
<li>More milk</li>
<li>More eggs</li>
</ul>
'''
))
self.assertContentStateEqual(result, {
'entityMap': {
'0': {
'data': {'format': 'left', 'alt': 'an image', 'id': '1', 'src': '/media/not-found'},
'mutability': 'IMMUTABLE', 'type': 'IMAGE'
},
},
'blocks': [
{'inlineStyleRanges': [], 'text': 'Milk', 'depth': 0, 'type': 'unordered-list-item', 'key': '00000', 'entityRanges': []},
{'inlineStyleRanges': [], 'text': 'Eggs', 'depth': 0, 'type': 'unordered-list-item', 'key': '00000', 'entityRanges': []},
{'key': '00000', 'inlineStyleRanges': [], 'entityRanges': [{'key': 1, 'offset': 0, 'length': 1}], 'depth': 0, 'text': ' ', 'type': 'atomic'},
{'inlineStyleRanges': [], 'text': 'More milk', 'depth': 0, 'type': 'unordered-list-item', 'key': '00000', 'entityRanges': []},
{'inlineStyleRanges': [], 'text': 'More eggs', 'depth': 0, 'type': 'unordered-list-item', 'key': '00000', 'entityRanges': []},
]
})
@patch('wagtail.embeds.embeds.get_embed')
def test_media_embed(self, get_embed):
get_embed.return_value = Embed(