A while ago, I wrote some code to do syntax highligting for doctest
blocks (including colorization of prompts & output). I don't have time
to write up a full patch right now, but I thought I'd post it in case
anyone else wants to run with it. It defines a generic
"colorize_doctest" function, which does all the hard work; each writer
just needs to call colorize_doctest() with an appropriate callback
function that will do the writer-specific formatting. For example, the
html writer just needs to add::
def visit_doctest_block(self, node):
pysrc = colorize_doctestblock(str(node), self._markup_pysrc)
def _markup_pysrc(self, s, tag):
return ('<span class="pysrc-%s">%s</span>' %
The colorize_doctest function would presumably live in some common
module that could be imported by different writers (I'm not sure where
this would be).
Get latest updates about Open Source Projects, Conferences and News.