gdesk.utils.syntax_light module

Add syntax highlighting to Python source code

gdesk.utils.syntax_light.alltt_escape(s)

Replace backslash and braces with their escaped equivalents

gdesk.utils.syntax_light.analyze_python(source)

Generate and classify chunks of Python for syntax highlighting. Yields tuples in the form: (category, categorized_text).

gdesk.utils.syntax_light.ansi_highlight(classified_text, colors={'builtin': ('\x1b[0;35m', '\x1b[0m'), 'comment': ('\x1b[0;31m', '\x1b[0m'), 'definition': ('\x1b[0;33m', '\x1b[0m'), 'defname': ('\x1b[0;34m', '\x1b[0m'), 'docstring': ('\x1b[0;32m', '\x1b[0m'), 'keyword': ('\x1b[0;33m', '\x1b[0m'), 'operator': ('\x1b[0;33m', '\x1b[0m'), 'string': ('\x1b[0;32m', '\x1b[0m')})

Add syntax highlighting to source code using ANSI escape sequences

gdesk.utils.syntax_light.build_html_page(classified_text, title='python', css={'.builtin': '{color: purple;}', '.comment': '{color: crimson;}', '.definition': '{color: darkorange; font-weight:bold;}', '.defname': '{color: blue;}', '.docstring': '{color: forestgreen; font-style:italic;}', '.keyword': '{color: darkorange;}', '.operator': '{color: brown;}', '.string': '{color: forestgreen;}'}, html='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"\n          "http://www.w3.org/TR/html4/strict.dtd">\n<html>\n<head>\n<meta http-equiv="Content-type" content="text/html;charset=UTF-8">\n<title> {title} </title>\n<style type="text/css">\n{css}\n</style>\n</head>\n<body>\n{body}\n</body>\n</html>\n')

Create a complete HTML page with colorized source code

gdesk.utils.syntax_light.combine_range(lines, start, end)

Join content from a range of lines between start and end

gdesk.utils.syntax_light.html_highlight(classified_text, opener='<pre class="python">\n', closer='</pre>\n')

Convert classified text to an HTML fragment

gdesk.utils.syntax_light.is_builtin(s)

Return True if s is the name of a builtin

gdesk.utils.syntax_light.latex_highlight(classified_text, title='python', commands={'builtin': '{\\color{purple}#1}', 'comment': '{\\color{red}#1}', 'definition': '{\\color{orange}#1}', 'defname': '{\\color{blue}#1}', 'docstring': '{\\emph{\\color{ForestGreen}#1}}', 'keyword': '{\\color{orange}#1}', 'operator': '{\\color{brown}#1}', 'string': '{\\color{ForestGreen}#1}'}, document='\n\\documentclass{article}\n\\usepackage{alltt}\n\\usepackage{upquote}\n\\usepackage{color}\n\\usepackage[usenames,dvipsnames]{xcolor}\n\\usepackage[cm]{fullpage}\n%(macros)s\n\\begin{document}\n\\center{\\LARGE{%(title)s}}\n\\begin{alltt}\n%(body)s\n\\end{alltt}\n\\end{document}\n')

Create a complete LaTeX document with colorized source code

gdesk.utils.syntax_light.raw_highlight(classified_text)

Straight text display of text classifications