def handleMatch(self, m): gist_id = m.group('gist_id') gist_file = m.group('filename') gist_elem = etree.Element('div') gist_elem.set('class', 'gist') script_elem = etree.SubElement(gist_elem, 'script') noscript_elem = etree.SubElement(gist_elem, 'noscript') try: if gist_file: script_elem.set('src', GIST_FILE_JS_URL.format(gist_id, gist_file)) raw_gist = (self.get_raw_gist_with_filename( gist_id, gist_file)) else: script_elem.set('src', GIST_JS_URL.format(gist_id)) raw_gist = (self.get_raw_gist(gist_id)) # Insert source as <pre/> within <noscript> pre_elem = etree.SubElement(noscript_elem, 'pre') pre_elem.text = AtomicString(raw_gist) except GistFetchException as e: LOGGER.warn(e.message) warning_comment = etree.Comment(' WARNING: {0} '.format(e.message)) noscript_elem.append(warning_comment) return gist_elem
def handle_comment(self, data): '''This method is called when a comment is encountered (e.g. <!--comment-->). Note: The content of Internet Explorer conditional comments (condcoms) will also be sent to this method. Args: data: The string of the comment. ''' element = etree.Comment(data) self.add_element(element)