Exemplo n.º 1
0
def test_inline_in_block_4():
    # Floats are pull to the top of their containing blocks
    source = '<p>Hello <em style="float: left">World</em>!</p>'
    box = parse(source)
    box = build.inline_in_block(box)
    box = build.block_in_inline(box)
    assert_tree(box, [('p', 'Block', [('p', 'Line', [
        ('p', 'Text', 'Hello '),
        ('em', 'Block', [('em', 'Line', [('em', 'Text', 'World')])]),
        ('p', 'Text', '!')
    ])])])
Exemplo n.º 2
0
def test_inline_in_block_3():
    # Absolutes are left in the lines to get their static position later.
    source = '''<p>Hello <em style="position:absolute;
                                    display: block">World</em>!</p>'''
    expected = [('p', 'Block', [('p', 'Line', [
        ('p', 'Text', 'Hello '),
        ('em', 'Block', [('em', 'Line', [('em', 'Text', 'World')])]),
        ('p', 'Text', '!')
    ])])]
    box = parse(source)
    box = build.inline_in_block(box)
    assert_tree(box, expected)
    box = build.block_in_inline(box)
    assert_tree(box, expected)
Exemplo n.º 3
0
def test_styles():
    box = parse('''
      <style>
        span { display: block; }
        * { margin: 42px }
        html { color: blue }
      </style>
      <p>Lorem <em>ipsum <strong>dolor <span>sit</span>
        <span>amet,</span></strong><span>consectetur</span></em></p>''')
    box = build.inline_in_block(box)
    box = build.block_in_inline(box)

    descendants = list(box.descendants())
    assert len(descendants) == 31
    assert descendants[0] == box

    for child in descendants:
        # All boxes inherit the color
        assert child.style['color'] == (0, 0, 1, 1)  # blue
        # Only non-anonymous boxes have margins
        assert child.style['margin_top'] in ((0, 'px'), (42, 'px'))
Exemplo n.º 4
0
def test_block_in_inline():
    box = parse('''
      <style>
        p { display: inline-block; }
        span, i { display: block; }
      </style>
      <p>Lorem <em>ipsum <strong>dolor <span>sit</span>
      <span>amet,</span></strong><span><em>conse<i>''')
    box = build.inline_in_block(box)
    assert_tree(
        box,
        [(
            'body',
            'Line',
            [(
                'p',
                'InlineBlock',
                [(
                    'p',
                    'Line',
                    [
                        ('p', 'Text', 'Lorem '),
                        (
                            'em',
                            'Inline',
                            [
                                ('em', 'Text', 'ipsum '),
                                (
                                    'strong',
                                    'Inline',
                                    [
                                        ('strong', 'Text', 'dolor '),
                                        (
                                            'span',
                                            'Block',
                                            [  # This block is "pulled up"
                                                ('span', 'Line', [
                                                    ('span', 'Text', 'sit')
                                                ])
                                            ]),
                                        ('strong', 'Text', ' '),
                                        (
                                            'span',
                                            'Block',
                                            [  # This block is "pulled up"
                                                ('span', 'Line', [
                                                    ('span', 'Text', 'amet,')
                                                ])
                                            ])
                                    ]),
                                (
                                    'span',
                                    'Block',
                                    [  # This block is "pulled up"
                                        ('span', 'Line', [('em', 'Inline', [
                                            ('em', 'Text', 'conse'),
                                            ('i', 'Block', [])
                                        ])])
                                    ])
                            ])
                    ])])])])

    box = build.block_in_inline(box)
    assert_tree(box, [('body', 'Line', [('p', 'InlineBlock', [
        ('p', 'Block', [
            ('p', 'Line', [('p', 'Text', 'Lorem '),
                           ('em', 'Inline', [('em', 'Text', 'ipsum '),
                                             ('strong', 'Inline', [
                                                 ('strong', 'Text', 'dolor ')
                                             ])])])
        ]), ('span', 'Block', [('span', 'Line', [('span', 'Text', 'sit')])]),
        ('p', 'Block', [('p', 'Line', [('em', 'Inline', [
            ('strong', 'Inline', [('strong', 'Text', ' ')])
        ])])]),
        ('span', 'Block', [('span', 'Line', [('span', 'Text', 'amet,')])]),
        ('p', 'Block', [
            ('p', 'Line', [('em', 'Inline', [('strong', 'Inline', [])])])
        ]),
        ('span', 'Block', [
            ('span', 'Block', [
                ('span', 'Line', [('em', 'Inline', [('em', 'Text', 'conse')])])
            ]), ('i', 'Block', []),
            ('span', 'Block', [('span', 'Line', [('em', 'Inline', [])])])
        ]), ('p', 'Block', [('p', 'Line', [('em', 'Inline', [])])])
    ])])])