view-source pygments feedback pass

This commit is contained in:
Markus Ongyerth 2018-03-01 16:13:00 +01:00
parent f7bcdfc818
commit 40364ce774
4 changed files with 15 additions and 16 deletions

View File

@ -150,15 +150,15 @@ class AbstractAction:
raise WebTabError("{} is not a valid web action!".format(name))
self._widget.triggerPageAction(member)
def show_source(self, pygment=False):
def show_source(self, pygments=False):
"""Show the source of the current page in a new tab."""
raise NotImplementedError
def _show_source_pygment(self):
def _show_source_pygments(self):
def show_source_cb(source):
"""show source as soon as it's ready."""
# workaround for https://github.com/pycqa/pylint/issues/491
"""Show source as soon as it's ready."""
# WORKAROUND for https://github.com/PyCQA/pylint/issues/491
# pylint: disable=no-member
lexer = pygments.lexers.HtmlLexer()
formatter = pygments.formatters.HtmlFormatter(

View File

@ -1513,12 +1513,15 @@ class CommandDispatcher:
)
@cmdutils.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('pygment')
def view_source(self, edit=False, pygment=False):
def view_source(self, edit=False, pygments=False):
"""Show the source of the current page in a new tab.
Args:
edit: Edit the source in the editor instead of opening a tab.
pygments: Use pygments to generate the view. This is always
the case for QtWebKit. For QtWebEngine it may display
slightly different source.
Some JavaScript processing may be applied.
"""
tab = self._current_widget()
try:
@ -1533,7 +1536,7 @@ class CommandDispatcher:
ed = editor.ExternalEditor(self._tabbed_browser)
tab.dump_async(ed.edit)
else:
tab.action.show_source(pygment)
tab.action.show_source(pygments)
@cmdutils.register(instance='command-dispatcher', scope='window',
debug=True)

View File

@ -100,9 +100,9 @@ class WebEngineAction(browsertab.AbstractAction):
"""Save the current page."""
self._widget.triggerPageAction(QWebEnginePage.SavePage)
def show_source(self, pygment):
if pygment:
self._show_source_pygment()
def show_source(self, pygments=False):
if pygments:
self._show_source_pygments()
return
try:

View File

@ -23,10 +23,6 @@ import re
import functools
import xml.etree.ElementTree
import pygments
import pygments.lexers
import pygments.formatters
import sip
from PyQt5.QtCore import (pyqtSlot, Qt, QEvent, QUrl, QPoint, QTimer, QSizeF,
QSize)
@ -55,8 +51,8 @@ class WebKitAction(browsertab.AbstractAction):
"""Save the current page."""
raise browsertab.UnsupportedOperationError
def show_source(self, pygment):
self._show_source_pygment()
def show_source(self, pygments=False):
self._show_source_pygments()
class WebKitPrinting(browsertab.AbstractPrinting):