1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-04 07:57:52 +03:00

Use the new box classes as appropriate (ie. for inline-block.)

This commit is contained in:
Simon Sapin 2011-05-25 15:27:30 +02:00
parent d971462153
commit ae62358854
2 changed files with 16 additions and 7 deletions

View File

@ -279,13 +279,14 @@ def dom_to_box(element):
display = element.style.display # TODO: should be the used value
assert display != 'none'
if display in ('block', 'list-item', 'table') \
or display.startswith('table-'):
# The element generates a block-level box
if display in ('block', 'list-item'):
box = BlockBox(element)
elif display in ('inline', 'inline-block', 'inline-table', 'ruby'):
# inline-level box
#if display == 'list-item':
# TODO: add a box for the marker
elif display == 'inline':
box = InlineBox(element)
elif display == 'inline-block':
box = InlineBlockBox(element)
else:
raise NotImplementedError('Unsupported display: ' + display)

View File

@ -34,6 +34,7 @@ def serialize(box_list):
types = {
boxes.BlockBox: 'block',
boxes.InlineBox: 'inline',
boxes.InlineBlockBox: 'inline_block',
boxes.TextBox: 'text',
boxes.AnonymousBlockBox: 'anon_block',
boxes.LineBox: 'line',
@ -107,11 +108,18 @@ def assert_tree(box, expected):
@suite.test
def test_box_tree():
assert_tree(parse('<p>'), [('p', 'block', [])])
assert_tree(parse('<p>Hello <em>World</em>!</p>'), [
assert_tree(parse('''
<style>
span { display: inline-block }
</style>
<p>Hello <em>World <span>Lipsum</span></em>!</p>
'''), [
('p', 'block', [
('p', 'text', 'Hello '),
('em', 'inline', [
('em', 'text', 'World')]),
('em', 'text', 'World '),
('span', 'inline_block', [
('span', 'text', 'Lipsum')])]),
('p', 'text', '!')])])