docx2html/core.py
def get_element_content(
        p,
        meta_data,
        is_td=False,
        remove_italics=False,
        remove_bold=False,
):
    """
    P tags are made up of several runs (r tags) of text. This function takes a
    p tag and constructs the text that should be part of the p tag.

    image_handler should be a callable that returns the desired ``src``
    attribute for a given image.
    """

    # Only remove bold or italics if this tag is an h tag.
    # Td elements have the same look and feel as p/h elements. Right now we are
    # never putting h tags in td elements, as such if we are in a td we will
    # never be stripping bold/italics since that is only done on h tags
    if not is_td and is_header(p, meta_data):
        # Check to see if the whole line is bold or italics.
        remove_bold, remove_italics = whole_line_styled(p)

    p_text = ''
    w_namespace = get_namespace(p, 'w')
    if len(p) == 0:
        return ''
    # Only these tags contain text that we care about (eg. We don't care about
    # delete tags)
    content_tags = (
        '%sr' % w_namespace,
        '%shyperlink' % w_namespace,
        '%sins' % w_namespace,
        '%ssmartTag' % w_namespace,
    )
    elements_with_content = []
    for child in p:
        if child is None:
            break
        if child.tag in content_tags:
            elements_with_content.append(child)

    # Gather the content from all of the children
    for el in elements_with_content:
        # Hyperlinks and insert tags need to be handled differently than
        # r and smart tags.
        if el.tag in ('%sins' % w_namespace, '%ssmartTag' % w_namespace):
            p_text += get_element_content(
                el,
                meta_data,
                remove_bold=remove_bold,
                remove_italics=remove_italics,
            )
        elif el.tag == '%shyperlink' % w_namespace:
            p_text += build_hyperlink(el, meta_data)
        elif el.tag == '%sr' % w_namespace:
            p_text += get_text_run_content(
                el,
                meta_data,
                remove_bold=remove_bold,
                remove_italics=remove_italics,
            )
        else:
            raise SyntaxNotSupported(
                'Content element "%s" not handled.' % el.tag
            )

    # This function does not return a p tag since other tag types need this as
    # well (td, li).
    return p_text
def get_element_content(
        p,
        meta_data,
        is_td=False,
        remove_italics=False,
        remove_bold=False,
):
    """
    P tags are made up of several runs (r tags) of text. This function takes a
    p tag and constructs the text that should be part of the p tag.

    image_handler should be a callable that returns the desired ``src``
    attribute for a given image.
    """

    # Only remove bold or italics if this tag is an h tag.
    # Td elements have the same look and feel as p/h elements. Right now we are
    # never putting h tags in td elements, as such if we are in a td we will
    # never be stripping bold/italics since that is only done on h tags
    if not is_td and is_header(p, meta_data):
        # Check to see if the whole line is bold or italics.
        remove_bold, remove_italics = whole_line_styled(p)

    p_text = ''
    w_namespace = get_namespace(p, 'w')
    if len(p) == 0:
        return ''
    # Only these tags contain text that we care about (eg. We don't care about
    # delete tags)
    content_tags = (
        '%sr' % w_namespace,
        '%shyperlink' % w_namespace,
        '%sins' % w_namespace,
        '%ssmartTag' % w_namespace,
    )
    elements_with_content = []
    for child in p:
        if child is None:
            break
        if child.tag in content_tags:
            elements_with_content.append(child)

    # Gather the content from all of the children
    for el in elements_with_content:
        # Hyperlinks and insert tags need to be handled differently than
        # r and smart tags.
        if el.tag in ('%sins' % w_namespace, '%ssmartTag' % w_namespace):
            p_text += get_element_content(
                el,
                meta_data,
                remove_bold=remove_bold,
                remove_italics=remove_italics,
            )
        elif el.tag == '%shyperlink' % w_namespace:
            p_text += build_hyperlink(el, meta_data)
        elif el.tag == '%sr' % w_namespace:
            p_text += get_text_run_content(
                el,
                meta_data,
                remove_bold=remove_bold,
                remove_italics=remove_italics,
            )
        else:
            raise SyntaxNotSupported(
                'Content element "%s" not handled.' % el.tag
            )

    # This function does not return a p tag since other tag types need this as
    # well (td, li).
    return p_text
def get_element_content ( p , meta_data , is_td = False , remove_italics = False , remove_bold = False , ) : # Only remove bold or italics if this tag is an h tag. # Td elements have the same look and feel as p/h elements. Right now we are # never putting h tags in td elements, as such if we are in a td we will # never be stripping bold/italics since that is only done on h tags if not is_td and is_header ( p , meta_data ) : # Check to see if the whole line is bold or italics. remove_bold , remove_italics = whole_line_styled ( p ) p_text = '' w_namespace = get_namespace ( p , 'w' ) if len ( p ) == 0 : return '' # Only these tags contain text that we care about (eg. We don't care about # delete tags) content_tags = ( '%sr' % w_namespace , '%shyperlink' % w_namespace , '%sins' % w_namespace , '%ssmartTag' % w_namespace , ) elements_with_content = [ ] for child in p : if child is None : break if child . tag in content_tags : elements_with_content . append ( child ) # Gather the content from all of the children for el in elements_with_content : # Hyperlinks and insert tags need to be handled differently than # r and smart tags. if el . tag in ( '%sins' % w_namespace , '%ssmartTag' % w_namespace ) : p_text += get_element_content ( el , meta_data , remove_bold = remove_bold , remove_italics = remove_italics , ) elif el . tag == '%shyperlink' % w_namespace : p_text += build_hyperlink ( el , meta_data ) elif el . tag == '%sr' % w_namespace : p_text += get_text_run_content ( el , meta_data , remove_bold = remove_bold , remove_italics = remove_italics , ) else : raise SyntaxNotSupported ( 'Content element "%s" not handled.' % el . tag ) # This function does not return a p tag since other tag types need this as # well (td, li). return p_text
P tags are made up of several runs (r tags) of text. This function takes a
    p tag and constructs the text that should be part of the p tag.

    image_handler should be a callable that returns the desired ``src``
    attribute for a given image.
P tags are made up of several runs ( r tags ) of text . This function takes a p tag and constructs the text that should be part of the p tag .