Beispiel #1
0
    def __init__(self, filename, book, status_bar):
        QApplication.setOverrideCursor(Qt.WaitCursor)
        self.filename = filename
        self.status_bar = status_bar

        html = "<html>\n<head>\n"
        html += "<link href=\"../css/pastie.css\" rel=\"stylesheet\" type=\"text/css\"/>\n"
        html += "<link href=\"../css/stylesheet.css\" rel=\"stylesheet\" type=\"text/css\"/>\n"
        html += "</head>\n<body>\n"
        for part in book._parts:
            self.status_bar.showMessage("Processing " + part.name)
            with open(os.path.join(book.source_path, "parts", part.src),
                      "r") as i:
                text = i.read()
                htm = markdown(text,
                               html4tags=False,
                               extras=[
                                   "fenced-code-blocks", "wiki-tables",
                                   "tables", "header-ids"
                               ])
                htm = addLineNumbers(htm)
                html += htm
        html += "\n</body>\n</html>"

        self.status_bar.showMessage("Loading HTML")
        self.page = QWebEnginePage()
        self.page.loadFinished.connect(self.loadFinished)
        self.page.pdfPrintingFinished.connect(self.printFinished)
        self.page.setHtml(
            html,
            QUrl(
                Path(os.path.join(book.source_path, "parts",
                                  "index.html")).as_uri()))
Beispiel #2
0
 def createHtml(self, text):
     html = "<html>\n<head>\n"
     html += "<link href=\"../css/pastie.css\" rel=\"stylesheet\" type=\"text/css\"/>\n"
     html += "<link href=\"../css/stylesheet.css\" rel=\"stylesheet\" type=\"text/css\"/>\n"
     html += "</head>\n<body>\n"
     html += markdown(text, html4tags=False, extras=["fenced-code-blocks", "wiki-tables", "tables", "header-ids"])
     html += "\n</body>\n</html>"
     html = addLineNumbers(html)
     self.htmlReady.emit(html)
Beispiel #3
0
def generateParts(book, xhtml):
    toc = []
    item = {}
    item["href"] = "toc.xhtml"
    if book.language == "de":
        item["name"] = "Inhaltsverzeichnis"
    else:
        item["name"] = "Table of Contents"
    item["id"] = "nav"
    item["parts"] = []
    toc.append(item)

    partNo = 1
    html = ""
    for part in book._parts:
        with open(os.path.join(book.source_path, "parts", part.src), "r") as i:
            text = i.read()
        name = part.name.replace(" ", "-").lower()
        htm = fixTables(
            markdown(text,
                     html4tags=False,
                     extras=[
                         "fenced-code-blocks", "wiki-tables", "tables",
                         "header-ids"
                     ]))
        list = getLinks(htm, name)
        for item in list:
            toc.append(item)
        htm = addLineNumbers(htm)
        # fix img tags
        book.source_path
        htm = htm.replace("../images",
                          "file://" + os.path.join(book.source_path, "images"))
        if partNo < len(book._parts):
            htm += "<p style=\"page-break-before: always\">"
        # should be true for cover page
        if part.pdfOnly:
            xhtml += htm
        else:
            html += htm
        partNo += 1

    return toc, html, xhtml