Пример #1
0
def test_parse_horizontal_align():
    html_element = HtmlElement()
    CssParse.attr_horizontal_align('center', html_element)
    assert html_element.align == HorizontalAlignment.center

    # invalid value
    CssParse.attr_horizontal_align('unknown', html_element)
    assert html_element.align == HorizontalAlignment.center
Пример #2
0
def test_parse_vertical_align():
    html_element = HtmlElement()
    CssParse.attr_vertical_align('top', html_element)
    assert html_element.valign == VerticalAlignment.top

    # invalid value
    CssParse.attr_vertical_align('unknown', html_element)
    assert html_element.valign == VerticalAlignment.top
Пример #3
0
def test_css_parsing():
    html_element = copy(CSS_PROFILES['strict']['div'])
    CssParse.attr_style('padding_left: 8px; display: block', html_element)
    assert html_element.padding_inline == 1
    assert html_element.display == Display.block

    CssParse.attr_style('margin_before: 8em; display: inline', html_element)
    assert html_element.margin_before == 8
    assert html_element.display == Display.inline
Пример #4
0
def test_css_parsing():
    css = CSS_PROFILES['strict'].copy()
    html_element = CssParse.get_style_attribute(
        'padding_left: 8px; '
        'display: block', css['div'])
    assert html_element.padding == 1
    assert html_element.display == Display.block

    html_element = CssParse.get_style_attribute(
        'margin_before: 8em; '
        'display: inline', css['div'])
    assert html_element.margin_before == 8
    assert html_element.display == Display.inline
Пример #5
0
    def handle_starttag(self, tag, attrs):
        '''
        Handels HTML start tags.

        Args:
          tag (str): the HTML start tag to process.
          attrs (dict): a dictionary of HTML attributes and their respective
             values.
        '''
        # use the css to handle tags known to it :)

        cur = self.css.get(tag, Inscriptis.DEFAULT_ELEMENT)
        if 'style' in attrs:
            cur = CssParse.get_style_attribute(attrs['style'],
                                               html_element=cur)
        self.current_tag.append(cur)
        if cur.display == Display.none or self.invisible:
            self.invisible.append(cur)
            return

        self.next_line[-1].padding = self.current_line[-1].padding \
            + cur.padding
        # flush text before display:block elements
        if cur.display == Display.block:
            if not self.write_line():
                self.current_line[-1].margin_before = max(
                    self.current_line[-1].margin_before, cur.margin_before)
                self.current_line[-1].padding = self.next_line[-1].padding
            else:
                self.current_line[-1].margin_after = max(
                    self.current_line[-1].margin_after, cur.margin_after)

        handler = self.start_tag_handler_dict.get(tag, None)
        if handler:
            handler(attrs)
Пример #6
0
def test_style_unit_parsing():
    html_element = CssParse.get_style_attribute(
        "margin-top:2.666666667em;margin-bottom: 2.666666667em",
        html_element=HtmlElement())
    assert html_element.margin_before == 3
    assert html_element.margin_after == 3