(html_body, html_content)
return html_body[:insert_index] + html_content + html_body[insert_index:]
Prepend some HTML content at the beginning of an other HTML content.
Prepend some HTML content at the beginning of an other HTML content.
Prepend some HTML content at the beginning of an other HTML content .
def prepend_html_content(html_body, html_content):
    """Prepend some HTML content at the beginning of an other HTML content."""
    html_content = type(html_content)(re.sub(r'(?i)(</?(?:html|body|head|!\s*DOCTYPE)[^>]*>)', '', html_content))
    html_content = html_content.strip()

    body_match = re.search(r'<body[^>]*>', html_body) or re.search(r'<html[^>]*>', html_body)
    insert_index = body_match.end() if body_match else 0

    return html_body[:insert_index] + html_content + html_body[insert_index:]
def prepend_html_content ( html_body , html_content ) : html_content = type ( html_content ) ( re . sub ( r'(?i)(</?(?:html|body|head|!\s*DOCTYPE)[^>]*>)' , '' , html_content ) ) html_content = html_content . strip ( ) body_match = re . search ( r'<body[^>]*>' , html_body ) or re . search ( r'<html[^>]*>' , html_body ) insert_index = body_match . end ( ) if body_match else 0 return html_body [ : insert_index ] + html_content + html_body [ insert_index : ]