def add_meta(xhtml, name, content): """ Add a meta tag. """ for head in gg.xpath(xhtml, '//xhtml:head'): meta = em.meta(name=name, content=content) meta.tail = '\n' head.append(meta)
def add_internal_css(xhtml, css_as_string): """ Add internal stylesheet to html. """ if css_as_string and xhtml is not None: css_as_string = '\n' + css_as_string.strip(' \n') + '\n' for head in gg.xpath(xhtml, '//xhtml:head'): style = em.style(css_as_string, type='text/css') style.tail = '\n' head.append(style)
def add_external_css(self, spider, xhtml, css_as_string, url): """ Add external stylesheet to html. """ if css_as_string: attribs = parsers.ParserAttributes() attribs.orig_mediatype = attribs.HeaderElement('text/css') attribs.url = attribs.orig_url = url p = ParserFactory.ParserFactory.get(attribs) p.parse_string(css_as_string) spider.parsers.append(p) if xhtml is not None: for head in gg.xpath(xhtml, '//xhtml:head'): link = em.link(href=url, rel='stylesheet', type='text/css') link.tail = '\n' head.append(link)
def add_body_class(xhtml, classname): """ Add a class to the body element. """ if classname and xhtml is not None: for body in gg.xpath(xhtml, '//xhtml:body'): HTMLishWriter.add_class(body, classname)