def createLexers(self): lex = {} lex['.c'] = CFamilyLexer() lex['.h'] = CFamilyLexer() lex['.cpp'] = CppLexer() lex['.hpp'] = CppLexer() lex['.css'] = CssLexer() lex['.sass'] = SassLexer() lex['.yaml'] = YamlLexer() lex['.yml'] = YamlLexer() lex['.json'] = JsonLexer() lex['.cs'] = CSharpLexer() lex['.fs'] = FSharpLexer() lex['.e'] = EiffelLexer() lex['.erl'] = ErlangLexer() lex['.hrl'] = ErlangLexer() lex['.es'] = ErlangLexer() lex['.f03'] = FortranLexer() lex['.f90'] = FortranLexer() lex['.F03'] = FortranLexer() lex['.F90'] = FortranLexer() lex['.go'] = GoLexer() lex['.hs'] = HaskellLexer() lex['.v'] = VerilogLexer() lex['.vhdl'] = VhdlLexer() lex['.vhd'] = VhdlLexer() lex['.html'] = HtmlLexer() lex['.htm'] = HtmlLexer() lex['.xhtml'] = HtmlLexer() lex['.xml'] = XmlLexer() lex['.js'] = JavascriptLexer() lex['.tex'] = TypeScriptLexer() lex['.coffee'] = CoffeeScriptLexer() lex['.java'] = JavaLexer() lex['.scala'] = ScalaLexer() lex['.kt'] = KotlinLexer() lex['.ktm'] = KotlinLexer() lex['.kts'] = KotlinLexer() lex['.lisp'] = CommonLispLexer() lex['make'] = MakefileLexer() lex['Make'] = MakefileLexer() lex['CMake'] = CMakeLexer() lex['cmake'] = CMakeLexer() lex['.m'] = MatlabLexer() lex['.mat'] = MatlabLexer() lex['.dpr'] = DelphiLexer() lex['.perl'] = PerlLexer() lex['.php'] = PhpLexer() lex['.pr'] = PrologLexer() lex['.py'] = Python3Lexer() lex['.rb'] = RubyLexer() lex['.sh'] = BashLexer() lex['.sql'] = MySqlLexer() lex['.mysql'] = MySqlLexer() lex['.tcl'] = TclLexer() lex['.awk'] = AwkLexer() return lex
def pretty_print(data, arg=None): """ :param data: :param arg: """ lexer = None if arg == 'JSON': data = json.dumps(json.loads(data), indent=2) lexer = JsonLexer() elif arg == 'XML': lexer = HtmlLexer() elif arg == 'ASCII': if not data.startswith(conf.error_marker): rows = data[1:].split("\n") rows = [r.replace('"', '').split(";") for r in rows if r] data = tabulate(rows, **conf.tabulate_opts) return click.echo_via_pager(data) else: return eprint(data) if lexer: tokens = list(pygments.lex(data, lexer=lexer)) print_formatted_text(PygmentsTokens(tokens)) else: print(data)
def print_data(data, fmt='json'): if fmt == 'html': lexer = HtmlLexer() else: lexer = JsonLexer() if not isinstance(data, str): data = json.dumps(data, indent=2) data = re.sub('14\d{8,11}', replace_data, data) print(highlight(data, lexer, formatter))
def POST(self): data = web.input() code = data.code language = data.lang if language == 'python': from pygments.lexers.python import PythonLexer lexer = PythonLexer() elif language == 'php': from pygments.lexers.php import PhpLexer lexer = PhpLexer() elif language == 'java': from pygments.lexers.jvm import JavaLexer lexer = JavaLexer() elif language == 'javascript': from pygments.lexers.javascript import JavascriptLexer lexer = JavascriptLexer() elif language == 'html': from pygments.lexers.html import HtmlLexer lexer = HtmlLexer() elif language == 'cpp': from pygments.lexers.c_cpp import CppLexer lexer = CppLexer() elif language == 'shell': from pygments.lexers.shell import ShellSessionLexer lexer = ShellSessionLexer() elif language == 'matlab': from pygments.lexers.matlab import MatlabLexer lexer = MatlabLexer() elif language == 'ruby': from pygments.lexers.ruby import RubyLexer lexer = RubyLexer() elif language == 'r': from pygments.lexers.r import RConsoleLexer lexer = RConsoleLexer() elif language == 'lisp': from pygments.lexers.lisp import SchemeLexer lexer = SchemeLexer() elif language == 'go': from pygments.lexers.go import GoLexer lexer = GoLexer() formatter = html.HtmlFormatter(linenos=False, encoding='utf-8', nowrap=False) hilighted_snippet = highlight(code, lexer, formatter) #return hilighted #return render.submit() return render.result(hilighted_snippet)
def _format_code(html_code): # syntax highlighting: code_highlighted = highlight( html_code, HtmlLexer(), HtmlFormatter(style='monokai', noclasses=True)) # add formatting for diff-markers: common_diff_style = ' margin-right: 3px; padding-right: 7px; padding-left: 7px;' code_formatted = code_highlighted \ .replace('[-', '<span style="background: #71332c;' + common_diff_style + '">') \ .replace('-]', '</span>') \ .replace('{+', '<span style="background: #2e4d28;' + common_diff_style + '">') \ .replace('+}', '</span>') # wrap in general layout: code_wrapped = '<div style="color: #efefef; margin: 3px; margin-left: 17px;line-height: 150%%;">%s</div>'\ %(code_formatted) return code_wrapped
def fill_htmlxml(self): from lxml import etree, html with DisableUpdates(self.htmlxml_widg): self.htmlxml_widg.setPlainText("") if not self.data: return try: fragments = html.fragments_fromstring(self.data.decode()) parsed_frags = [] for f in fragments: parsed_frags.append(etree.tostring(f, pretty_print=True)) pretty = b''.join(parsed_frags) except Exception: return highlighted = textedit_highlight(pretty, HtmlLexer()) self.htmlxml_widg.setHtml(highlighted)
def __init__(self): QDialog.__init__(self) self.resize(1200, 400) self.setWindowTitle('TkPy3 Markdown转换器') self.layout = QGridLayout(self) self.file_name = '' self.view_frame = QWidget() self.view_layout = QHBoxLayout() self.view_splitter = QSplitter(Qt.Horizontal) self.view_frame.setLayout(self.view_layout) self.loadMarkdown_file_button = QPushButton() self.show_file_name = QLabel() self.text_view = QTextBrowser() self.html_view = QWebEngineView() self.save_button = QPushButton() PygmentsHighlighter(self.text_view, HtmlLexer()) self.init_ui()
from home import HomeTab from text.tktextext import EnhancedText from gui.scrollbar_autohide import AutoHideScrollbar from collections import deque from console import ConsoleUi, Processing # python3 -m pip download --only-binary=wheel pygments # sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)) + '/vendor/pygments') # pylint: disable=too-many-ancestors # TODO: Legg inn sjekk på shebang også: https://kite.com/python/docs/pygments.lexers.ruby.shebang_matches lexer_from_ext = { # WAIT: Denne bør hentes fra configfil heller 'py': PythonLexer(), 'pyw': PythonLexer(), 'htm': HtmlLexer(), 'html': HtmlLexer(), 'xml': XmlLexer(), # WAIT: Se om finnes bedre 'xsl': XmlLexer(), 'rss': XmlLexer(), 'xslt': XmlLexer(), 'xsd': XmlLexer(), 'wsdl': XmlLexer(), 'php': HtmlPhpLexer(), 'php5': HtmlPhpLexer(), 'pl': Perl6Lexer(), 'pm': Perl6Lexer(), 'nqp': Perl6Lexer(), 'p6': Perl6Lexer(), '6pl': Perl6Lexer(), 'p6l': Perl6Lexer(),
def lexer_html(): yield HtmlLexer()
def build(self): codeinput = CodeInput(lexer=HtmlLexer()) return codeinput
if __name__ == "__main__": extens = "" try: extens = sys.argv[1].split('.')[1] except IndexError: pass if extens == "py" or extens == "pyw" or extens == "sc" or extens == "sage" or extens == "tac": ui_core = CoreUI(lexer=PythonLexer()) elif extens == "txt" or extens == "README" or extens == "text": ui_core = CoreUI(lexer=TextLexer()) elif extens == "htm" or extens == "html" or extens == "css" or extens == "js" or extens == "md": ui_core = CoreUI(lexer=HtmlLexer()) elif extens == "xml" or extens == "xsl" or extens == "rss" or extens == "xslt" or extens == "xsd" or extens == "wsdl" or extens == "wsf": ui_core = CoreUI(lexer=XmlLexer()) elif extens == "php" or extens == "php5": ui_core = CoreUI(lexer=HtmlPhpLexer()) elif extens == "pl" or extens == "pm" or extens == "nqp" or extens == "p6" or extens == "6pl" or extens == "p6l" or extens == "pl6" or extens == "pm" or extens == "p6m" or extens == "pm6" or extens == "t": ui_core = CoreUI(lexer=Perl6Lexer()) elif extens == "rb" or extens == "rbw" or extens == "rake" or extens == "rbx" or extens == "duby" or extens == "gemspec": ui_core = CoreUI(lexer=RubyLexer()) elif extens == "ini" or extens == "init": ui_core = CoreUI(lexer=IniLexer()) elif extens == "conf" or extens == "cnf" or extens == "config": ui_core = CoreUI(lexer=ApacheConfLexer()) elif extens == "sh" or extens == "cmd" or extens == "bashrc" or extens == "bash_profile": ui_core = CoreUI(lexer=BashLexer()) elif extens == "diff" or extens == "patch":