diff options
Diffstat (limited to 'sandbox/code-block-directive/tools')
6 files changed, 83 insertions, 66 deletions
diff --git a/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/README.txt b/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/README.txt index 5f5e77557..aa68c3d11 100644 --- a/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/README.txt +++ b/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/README.txt @@ -33,6 +33,10 @@ Disadvantages: - no "minimal" code block marker -- three additional lines per code block +The disadvantages lead to the alternative implementation with the +demonstrator front ends `rst2html-highlight`_ and `rst2latex-highlight`_. + + Example """"""" @@ -54,10 +58,12 @@ Stylesheets: .. _rst2html-pygments: rst2html-pygments .. _rst2latex-pygments: rst2latex-pygments +.. _rst2html-highlight: ../../rst2html-highlight +.. _rst2latex-highlight: ../../rst2latex-highlight .. _for-else-test: .. _for-else-test.py.htm: for-else-test.py.htm .. _for-else-test.py.txt: for-else-test.py.txt .. _for-else-test.py.tex: for-else-test.py.tex .. _for-else-test.py.pdf: for-else-test.py.pdf -.. _pygments-default.css: ../data/pygments-default.css -.. _pygments-default.sty: ../data/pygments-default.sty +.. _pygments-default.css: ../../data/pygments-default.css +.. _pygments-default.sty: ../../data/pygments-default.sty diff --git a/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/for-else-test.py.pdf b/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/for-else-test.py.pdf Binary files differindex b8e63b5e8..fa39a5967 100644 --- a/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/for-else-test.py.pdf +++ b/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/for-else-test.py.pdf diff --git a/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/for-else-test.py.tex b/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/for-else-test.py.tex index b664d4865..e16a5dd71 100644 --- a/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/for-else-test.py.tex +++ b/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/for-else-test.py.tex @@ -1,20 +1,20 @@ -\documentclass[10pt,a4paper,english]{article} +\documentclass[10pt,a4paper,english]{scrartcl} \usepackage{babel} -\usepackage{ae} -\usepackage{aeguill} +\usepackage[T1]{fontenc} \usepackage{shortvrb} -\usepackage[latin1]{inputenc} +\usepackage{ucs} +\usepackage[utf8x]{inputenc} \usepackage{tabularx} \usepackage{longtable} +\usepackage{booktabs} \setlength{\extrarowheight}{2pt} \usepackage{amsmath} \usepackage{graphicx} \usepackage{color} \usepackage{multirow} \usepackage{ifthen} -\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref} -\usepackage[DIV12]{typearea} -%% generator Docutils: http://docutils.sourceforge.net/ +\typearea{12} +% generated by Docutils <http://docutils.sourceforge.net/> \newlength{\admonitionwidth} \setlength{\admonitionwidth}{0.9\textwidth} \newlength{\docinfowidth} @@ -55,7 +55,11 @@ \newcommand{\rubric}[1]{\subsection*{~\hfill {\it #1} \hfill ~}} \newcommand{\titlereference}[1]{\textsl{#1}} % end of "some commands" -\input{pygments-default.sty} +% user specified packages and stylesheets: +\usepackage{../../data/pygments-default} +\ifthenelse{\isundefined{\hypersetup}}{ +\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue]{hyperref} +}{} \title{Example for syntax highlight with Pygments} \author{} \date{} @@ -66,22 +70,33 @@ pdftitle={Example for syntax highlight with Pygments} \begin{document} \maketitle - \setlength{\locallinewidth}{\linewidth} -% # -*- rst-mode -*- Translate this document to HTML with a pygments enhanced frontend: -\begin{quote}{\ttfamily \raggedright \noindent -rst2html-pygments~-{}-stylesheet=pygments-default.css -}\end{quote} +\begin{quote}\begin{verbatim} +rst2html-pygments --stylesheet=pygments-default.css +\end{verbatim} +\end{quote} or to LaTeX with: -\begin{quote}{\ttfamily \raggedright \noindent -rst2latex-pygments~-{}-stylesheet=pygments-default.sty -}\end{quote} +\begin{quote}\begin{verbatim} +rst2latex-pygments --stylesheet=pygments-default.sty +\end{verbatim} +\end{quote} to gain syntax highlight in the output. -% Run the doctests with ``pylit --doctest for-else-test.py``. + +Convert between text {\textless}-{\textgreater} code source formats with: +\begin{quote}\begin{verbatim} +pylit --code-block-marker='.. code-block:: python' +\end{verbatim} +\end{quote} + +Run the doctests with: +\begin{quote}\begin{verbatim} +pylit --doctest for-else-test.py +\end{verbatim} +\end{quote} %___________________________________________________________________________ @@ -89,78 +104,67 @@ to gain syntax highlight in the output. \hypertarget{for-else-test}{} \pdfbookmark[0]{for-else-test}{for-else-test} \section*{for-else-test} +\label{for-else-test} Test the flow in a \titlereference{for} loop with \titlereference{else} statement. First define a simple \titlereference{for} loop. \begin{Verbatim}[commandchars=@\[\]] -@Cax[def] @CaJ[loop1](iterable): - @Car["""simple for loop with `else` statement"""] - @Cax[for] i @Cam[in] iterable: - @Cax[print] i - @Cax[else]: - @Cax[print] @Cad["]@Cad[iterable empty]@Cad["] - @Cax[print] @Cad["]@Cad[Ende]@Cad["] - +@PYay[def] @PYaK[loop1](iterable): + @PYas["""simple for loop with `else` statement"""] + @PYay[for] i @PYan[in] iterable: + @PYay[print] i + @PYay[else]: + @PYay[print] @PYad["]@PYad[iterable empty]@PYad["] + @PYay[print] @PYad["]@PYad[Ende]@PYad["] \end{Verbatim} Now test it: The first test runs as I expect: iterator empty -{\textgreater} else clause applies: \begin{Verbatim}[commandchars=@\[\]] -@CaN[>>> ]loop1(@CaW[range](@Cag[0])) -@Caa[iterable empty] -@Caa[Ende] - +@PYaO[>>> ]@PYaX[execfile](@PYad[']@PYad[for-else-test.py]@PYad[']) +@PYaO[>>> ]loop1(@PYaX[range](@PYaw[0])) +@PYaa[iterable empty] +@PYaa[Ende] \end{Verbatim} However, the else clause even runs if the iterator is not empty in the first place but after it is ``spent'': \begin{Verbatim}[commandchars=@\[\]] -@CaN[>>> ]loop1(@CaW[range](@Cag[3])) -@Caa[0] -@Caa[1] -@Caa[2] -@Caa[iterable empty] -@Caa[Ende] - +@PYaO[>>> ]loop1(@PYaX[range](@PYaw[3])) +@PYaa[0] +@PYaa[1] +@PYaa[2] +@PYaa[iterable empty] +@PYaa[Ende] \end{Verbatim} It seems like the else clause can only be prevented, if we break out of the loop. Let's try \begin{Verbatim}[commandchars=@\[\]] -@Cax[def] @CaJ[loop2](iterable): - @Car["""for loop with `break` and `else` statement"""] - @Cax[for] i @Cam[in] iterable: - @Cax[print] i - @Cax[break] - @Cax[else]: - @Cax[print] @Cad["]@Cad[iterable empty]@Cad["] - @Cax[print] @Cad["]@Cad[Ende]@Cad["] - +@PYay[def] @PYaK[loop2](iterable): + @PYas["""for loop with `break` and `else` statement"""] + @PYay[for] i @PYan[in] iterable: + @PYay[print] i + @PYay[break] + @PYay[else]: + @PYay[print] @PYad["]@PYad[iterable empty]@PYad["] + @PYay[print] @PYad["]@PYad[Ende]@PYad["] \end{Verbatim} And indeed, the else clause is skipped after breaking out of the loop: \begin{Verbatim}[commandchars=@\[\]] -@CaN[>>> ]loop2(@CaW[range](@Cag[3])) -@Caa[0] -@Caa[Ende] - +@PYaO[>>> ]loop2(@PYaX[range](@PYaw[3])) +@PYaa[0] +@PYaa[Ende] \end{Verbatim} The empty iterator runs as expected: \begin{Verbatim}[commandchars=@\[\]] -@CaN[>>> ]loop2(@CaW[range](@Cag[0])) -@Caa[iterable empty] -@Caa[Ende] - +@PYaO[>>> ]loop2(@PYaX[range](@PYaw[0])) +@PYaa[iterable empty] +@PYaa[Ende] \end{Verbatim} -\begin{center}\small - -Generated on: 2007-04-24. - - -\end{center} - \end{document} diff --git a/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/rst2html-pygments b/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/rst2html-pygments index c227bbf2e..706b25980 100755 --- a/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/rst2html-pygments +++ b/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/rst2html-pygments @@ -1,6 +1,6 @@ #!/usr/bin/python -# :Author: David Goodger, a Pygments author|contributor, Guenter Milde +# :Author: David Goodger, the Pygments team, Guenter Milde # :Date: $Date: $ # :Copyright: This module has been placed in the public domain. diff --git a/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/rst2latex-pygments b/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/rst2latex-pygments index f52fc167f..c53c2aa74 100755 --- a/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/rst2latex-pygments +++ b/sandbox/code-block-directive/tools/pygments-enhanced-front-ends/rst2latex-pygments @@ -1,6 +1,6 @@ #!/usr/bin/python -# Author: David Goodger, a Pygments author|contributor, Guenter Milde +# Author: David Goodger, the Pygments team, Günter Milde # Date: $Date: $ # Copyright: This module has been placed in the public domain. diff --git a/sandbox/code-block-directive/tools/test_pygments_code_block_directive.py b/sandbox/code-block-directive/tools/test_pygments_code_block_directive.py index b130a7b2f..9d0ea510a 100755 --- a/sandbox/code-block-directive/tools/test_pygments_code_block_directive.py +++ b/sandbox/code-block-directive/tools/test_pygments_code_block_directive.py @@ -3,7 +3,7 @@ # Test the parsing and formatting by pygments: -# :Author: Felix Wiemann; Guenter Milde +# :Author: Felix Wiemann; Günter Milde # :Date: $Date$ # :Copyright: This module has been placed in the public domain. @@ -11,6 +11,13 @@ # ------------ from docutils import nodes, utils, core + +# Prepend parent dir to the PYTHONPATH (This is a hack to get this test +# working without installing the pygments_code_block_directive module. +# Not needed if the module is installed in the PYTHONPATH) +import sys +sys.path.insert(0, '..') + from pygments_code_block_directive import DocutilsInterface # Test data @@ -51,7 +58,7 @@ for cls, value in DocutilsInterface(code_sample, language): # ----- writer_names = ('html', 'pseudoxml', 'xml', 'latex', 'newlatex2e', 's5') -for name in writer_names[2:3]: +for name in writer_names[:]: print "\nusing writer %r\n" % name print core.publish_from_doctree(document, writer_name=name) |