Beispiel #1
0
    def convert(self, text):
        import asciidoc
        from lxml import etree

        outfile = StringIO()
        infile = StringIO(text)
        opts = [
            ("--backend", "html5"),
            ("--attribute", r"newline=\n"),
            ("--attribute", "footer-style=none"),
            ("--out-file", outfile),
        ]
        try:
            asciidoc.execute(None, opts, [infile])
        except SystemExit as ex:
            warnings.warn(ex.__context__, SyntaxWarning)
            pass
        result = outfile.getvalue()
        parser = etree.HTMLParser()
        root_element = etree.fromstring(result, parser)
        head_element = root_element.xpath("./head")[0]
        title_element = root_element.xpath("./head/title")[0]
        style_elements = root_element.xpath("./head/style")
        javascript_elements = root_element.xpath("./head/script")
        body_element = root_element.xpath("./body")[0]
        head = ""
        for child in head_element.getchildren():
            head += etree.tostring(
                child,
                encoding="unicode",
                method="html",
            )
        body = ""
        for child in body_element.getchildren():
            body += etree.tostring(
                child,
                encoding="unicode",
                method="html",
            )
        title = title_element.text
        stylesheet = ""
        for style_element in style_elements:
            stylesheet += style_element.text
        javascript = ""
        for javascript_element in javascript_elements:
            javascript += etree.tostring(
                javascript_element,
                encoding="unicode",
                method="html",
            )
        return ConvertedMarkup(body, title, stylesheet, javascript)
Beispiel #2
0
 def get_result(self):
     return ConvertedMarkup('')
 def __init__(self, head, body, title, stylesheet):
     ConvertedMarkup.__init__(self, body, title, stylesheet)
     self.head = head
Beispiel #4
0
 def convert(self, text):
     return ConvertedMarkup(self.textile(text))
 def __init__(self, head, body, title, stylesheet):
     ConvertedMarkup.__init__(self, body, title, stylesheet)
     self.head = head