r''' resolve_js_require handles the js-require attribute, adding Note that the html/head/body tags can be added by the HTML parser, and the tag is added by the HTML serializer. A more complicated test:: >>> test(""" ... ... ... ... ... """) ''' from lxml import etree from urlparse import urljoin def resolve_js_require(doc, doc_url, find_library_url): if isinstance(doc, basestring): doc = etree.HTML(doc) script_hrefs = set() for el in doc.xpath('//*[@js-require]'): name = el.attrib['js-require'] del el.attrib['js-require'] url = find_library_url(name, 'js') script_hrefs.add(url) # Check that we aren't duplicating any explicit