diff --git a/qutebrowser/html/base.html b/qutebrowser/html/base.html index 51bf2f431..699740025 100644 --- a/qutebrowser/html/base.html +++ b/qutebrowser/html/base.html @@ -1,5 +1,7 @@ - + diff --git a/qutebrowser/html/log.html b/qutebrowser/html/log.html new file mode 100644 index 000000000..a2d3bad6f --- /dev/null +++ b/qutebrowser/html/log.html @@ -0,0 +1,35 @@ +{% extends "base.html" %} + +{% block style %} +body { + background-color: black; + color: white; + font-size: 11px; +} + +table { + border: 1px solid grey; + border-collapse: collapse; +} + +pre { + margin: 2px; +} + +th, td { + border: 1px solid grey; + padding-left: 5px; + padding-right: 5px; +} +{% endblock %} + +{% block content %} +{{ super() }} +{% if content %} + +{{ content | safe() }} +
+{% else %} +

Log output was disabled.

+{% endif %} +{% endblock %} diff --git a/qutebrowser/network/qutescheme.py b/qutebrowser/network/qutescheme.py index 83f54fe23..66adefb18 100644 --- a/qutebrowser/network/qutescheme.py +++ b/qutebrowser/network/qutescheme.py @@ -20,12 +20,9 @@ """Handler functions for different qute:... pages. Module attributes: - _HTML_TEMPLATE: The HTML boilerplate used to convert text into html. pyeval_output: The output of the last :pyeval command. """ -import html as pyhtml - from PyQt5.QtNetwork import QNetworkReply import qutebrowser @@ -34,42 +31,9 @@ from qutebrowser.utils import version, utils, jinja from qutebrowser.utils import log as logutils -_HTML_TEMPLATE = """ - - - - - {title} - {head} - - -{body} - - -""" - - pyeval_output = ":pyeval was never called" -def _get_html(title, snippet, head=None): - """Add HTML boilerplate to a html snippet. - - Args: - title: The title the page should have. - snippet: The html snippet. - head: Additional stuff to put in - - Return: - HTML content as bytes. - """ - if head is None: - head = "" - html = _HTML_TEMPLATE.format(title=title, body=snippet, head=head).encode( - 'UTF-8', errors='xmlcharrefreplace') - return html - - class QuteSchemeHandler(schemehandler.SchemeHandler): """Scheme handler for qute: URLs.""" @@ -136,35 +100,13 @@ class QuteHandlers: @classmethod def log(cls): """Handler for qute:log. Return HTML content as bytes.""" - style = """ - - """ if logutils.ram_handler is None: - html = "

Log output was disabled.

" + html_log = None else: - html = logutils.ram_handler.dump_log(html=True) - return _get_html('log', html, head=style) + html_log = logutils.ram_handler.dump_log(html=True) + html = jinja.env.get_template('log.html').render( + title='log', content=html_log) + return html.encode('UTF-8', errors='xmlcharrefreplace') @classmethod def gpl(cls): diff --git a/qutebrowser/utils/log.py b/qutebrowser/utils/log.py index 72b1bce11..c05352126 100644 --- a/qutebrowser/utils/log.py +++ b/qutebrowser/utils/log.py @@ -317,13 +317,12 @@ class RAMHandler(logging.Handler): self.data.append(record) def dump_log(self, html=False): - """Dump the complete formatted log data as as string.""" - if html: - fmt = self.html_formatter.format - lines = [''] - else: - fmt = self.format - lines = [] + """Dump the complete formatted log data as as string. + + FIXME: We should do all the HTML formatter via jinja2. + """ + lines = [] + fmt = self.html_formatter.format if html else self.format self.acquire() try: records = list(self.data) @@ -331,8 +330,6 @@ class RAMHandler(logging.Handler): self.release() for record in records: lines.append(fmt(record)) - if html: - lines.append('
') return '\n'.join(lines) diff --git a/qutebrowser/utils/version.py b/qutebrowser/utils/version.py index ea38b0488..2eb2a9579 100644 --- a/qutebrowser/utils/version.py +++ b/qutebrowser/utils/version.py @@ -48,25 +48,6 @@ along with this program. If not, see or use :open qute:gpl. """ -GPL_BOILERPLATE_HTML = """ -

-This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. -

-

-This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. -

-

-You should have received a copy of the GNU General Public License -along with this program. If not, see -http://www.gnu.org/licenses/ or open qute:gpl. -""" - def _git_str(): """Try to find out git version.