Maintaining good documentation for Python programs using HTML is quite tedious and annoying, despite useful utilities such as pydoc. Therefore, we will attempt to write an import filter for Python which extracts relevant passages in XHTML documents in order to execute them. This should allow us to write the documentation and code in the same document, hopefully making maintenance a lot easier.
The following preformatted text illustrates what we are trying to achive. We have written a simple program in Python which we aim to execute without having to manually extract the text first.
This is a docstring which will be included in the source code.
# This is some Python code in a preformatted text area. def hello(): for i in range(1, 11): print "Hello %i" % i
After the preformatted text has finished, normal text resumes.
Preformatted text which is not Python code is defined without the use the "Python" class attribute. For example,
<pre>Some text which is not Python code.</pre> <pre class="Python"> # Some text which is Python code. </pre>