Beispiel #1
0
    def preformat_chunk(self, chunk):
        if chunk["type"] == "doc":
            return chunk

        from pygments import highlight
        from IPython.lib.lexers import IPyLexer
        #from pygments.lexers import PythonLexer, PythonConsoleLexer, TextLexer
        from pygments.formatters import HtmlFormatter

        chunk['content'] = highlight(chunk['content'], IPyLexer(),
                                     HtmlFormatter())
        return chunk
Beispiel #2
0
    def format_codechunks(self, chunk):
        from pygments import highlight
        from IPython.lib.lexers import IPyLexer

        # from pygments.lexers import PythonLexer, TextLexer, PythonConsoleLexer
        from pygments.formatters import LatexFormatter

        chunk["content"] = highlight(
            chunk["content"],
            IPyLexer(),
            LatexFormatter(
                verboptions="frame=single,fontsize=\small, xleftmargin=0.5em"),
        )
        return PwebFormatter.format_codechunks(self, chunk)
Beispiel #3
0
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False

# The name of the Pygments (syntax highlighting) style to use.  NOTE:
# This overrides a HTML theme's corresponding setting (see below).
pygments_style = 'sphinx'

# Default lexer to use when highlighting code blocks, using the IPython
# console lexers. 'ipycon' is the IPython console, which is what we want
# for most code blocks: anything with "sage:" prompts. For other IPython,
# like blocks which might appear in a notebook cell, use 'ipython'.
highlighting.lexers['ipycon'] = IPythonConsoleLexer(
    in1_regex=r'sage: ', in2_regex=r'[.][.][.][.]: ')
highlighting.lexers['ipython'] = IPyLexer()
highlight_language = 'ipycon'

# GraphViz includes dot, neato, twopi, circo, fdp.
graphviz_dot = 'dot'
inheritance_graph_attrs = {'rankdir': 'BT'}
inheritance_node_attrs = {'height': 0.5, 'fontsize': 12, 'shape': 'oval'}
inheritance_edge_attrs = {}

# Extension configuration
# -----------------------

# include the todos
todo_include_todos = True

# Cross-links to other project's online documentation.
Beispiel #4
0
"""
reST directive for syntax-highlighting ipython interactive sessions.

"""

from IPython.lib.lexers import IPyLexer

from sphinx import highlighting


def setup(app):
    """Setup as a sphinx extension."""

    # This is only a lexer, so adding it below to pygments appears sufficient.
    # But if somebody knows what the right API usage should be to do that via
    # sphinx, by all means fix it here.  At least having this setup.py
    # suppresses the sphinx warning we'd get without it.
    metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
    return metadata

# Register the extension as a valid pygments lexer.
# Alternatively, we could register the lexer with pygments instead. This would
# require using setuptools entrypoints: http://pygments.org/docs/plugins

ipy2 = IPyLexer(python3=False)
ipy3 = IPyLexer(python3=True)

highlighting.lexers['ipython'] = ipy2
highlighting.lexers['ipython2'] = ipy2
highlighting.lexers['ipython3'] = ipy3