def complex_document(self, nodes, heads=False): """Create a complex document.""" doc = QtGui.QTextDocument() doc.setDefaultStyleSheet(self.stylesheet) contents = '' for n in nodes: if heads: contents += '<h1>%s</h1>\n' % (self.sanitize_html(n.h)) contents += '<pre>%s</pre>\n' % (self.sanitize_html(n.b)) doc.setHtml(contents) return doc
def document(self, text, head=None): """Create a Qt document.""" doc = QtGui.QTextDocument() doc.setDefaultStyleSheet(self.stylesheet) text = self.sanitize_html(text) if head: head = self.sanitize_html(head) contents = "<h1>%s</h1>\n<pre>%s</pre>" % (head, text) else: contents = f"<pre>{text}<pre>" doc.setHtml(contents) return doc
def html_document(self, text): """Create an HTML document.""" doc = QtGui.QTextDocument() doc.setDefaultStyleSheet(self.stylesheet) doc.setHtml(text) return doc