Show More
@@ -549,9 +549,11 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||||
549 | # N.B. this is overly restrictive, but Qt's output is |
|
549 | # N.B. this is overly restrictive, but Qt's output is | |
550 | # predictable... |
|
550 | # predictable... | |
551 | img_re = re.compile(r'<img src="(?P<name>[\d]+)" />') |
|
551 | img_re = re.compile(r'<img src="(?P<name>[\d]+)" />') | |
|
552 | html = self.fix_html_encoding( | |||
|
553 | str(self._control.toHtml().toUtf8())) | |||
552 | f.write(img_re.sub( |
|
554 | f.write(img_re.sub( | |
553 | lambda x: self.image_tag(x, path = path, format = "png"), |
|
555 | lambda x: self.image_tag(x, path = path, format = "png"), | |
554 | str(self._control.toHtml().toUtf8()))) |
|
556 | html)) | |
555 | finally: |
|
557 | finally: | |
556 | f.close() |
|
558 | f.close() | |
557 | return filename |
|
559 | return filename | |
@@ -578,6 +580,8 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||||
578 | assert(offset > -1) |
|
580 | assert(offset > -1) | |
579 | html = ('<html xmlns="http://www.w3.org/1999/xhtml">\n'+ |
|
581 | html = ('<html xmlns="http://www.w3.org/1999/xhtml">\n'+ | |
580 | html[offset+6:]) |
|
582 | html[offset+6:]) | |
|
583 | # And now declare UTF-8 encoding | |||
|
584 | html = self.fix_html_encoding(html) | |||
581 | f.write(img_re.sub( |
|
585 | f.write(img_re.sub( | |
582 | lambda x: self.image_tag(x, path = None, format = "svg"), |
|
586 | lambda x: self.image_tag(x, path = None, format = "svg"), | |
583 | html)) |
|
587 | html)) | |
@@ -586,6 +590,29 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||||
586 | return filename |
|
590 | return filename | |
587 | return None |
|
591 | return None | |
588 |
|
592 | |||
|
593 | def fix_html_encoding(self, html): | |||
|
594 | """ Return html string, with a UTF-8 declaration added to <HEAD>. | |||
|
595 | ||||
|
596 | Assumes that html is Qt generated and has already been UTF-8 encoded | |||
|
597 | and coerced to a python string. If the expected head element is | |||
|
598 | not found, the given object is returned unmodified. | |||
|
599 | ||||
|
600 | This patching is needed for proper rendering of some characters | |||
|
601 | (e.g., indented commands) when viewing exported HTML on a local | |||
|
602 | system (i.e., without seeing an encoding declaration in an HTTP | |||
|
603 | header). | |||
|
604 | ||||
|
605 | C.f. http://www.w3.org/International/O-charset for details. | |||
|
606 | """ | |||
|
607 | offset = html.find("<head>") | |||
|
608 | if(offset > -1): | |||
|
609 | html = (html[:offset+6]+ | |||
|
610 | '\n<meta http-equiv="Content-Type" '+ | |||
|
611 | 'content="text/html; charset=utf-8" />\n'+ | |||
|
612 | html[offset+6:]) | |||
|
613 | ||||
|
614 | return html | |||
|
615 | ||||
589 | def image_tag(self, match, path = None, format = "png"): |
|
616 | def image_tag(self, match, path = None, format = "png"): | |
590 | """ Return (X)HTML mark-up for the image-tag given by match. |
|
617 | """ Return (X)HTML mark-up for the image-tag given by match. | |
591 |
|
618 |
General Comments 0
You need to be logged in to leave comments.
Login now