(html_file)
Embed a CSS file in the HTML.
Embed a CSS file in the HTML.
Embed a CSS file in the HTML .
def _embed_style(html_file):
    """Embed a CSS file in the HTML."""
    parser = etree.HTMLParser(encoding='utf-8')
    doc = etree.parse(html_file, parser)
    for node in doc.xpath('//link[@rel="stylesheet"]'):
        href = node.get('href')
        css = os.path.join(BASEPATH, href)
        node.tag = 'style'
        node.text = '\n' + read_file(css) + '\n    '
        node.attrib.clear()
        node.set('id', href)
    with open(html_file, 'w', encoding='utf-8') as f:
        f.write(etree.tostring(doc, method="html").decode('utf-8'))
def _embed_style ( html_file ) : parser = etree . HTMLParser ( encoding = 'utf-8' ) doc = etree . parse ( html_file , parser ) for node in doc . xpath ( '//link[@rel="stylesheet"]' ) : href = node . get ( 'href' ) css = os . path . join ( BASEPATH , href ) node . tag = 'style' node . text = '\n' + read_file ( css ) + '\n    ' node . attrib . clear ( ) node . set ( 'id' , href ) with open ( html_file , 'w' , encoding = 'utf-8' ) as f : f . write ( etree . tostring ( doc , method = "html" ) . decode ( 'utf-8' ) )