|
From: David G. <go...@us...> - 2002-08-15 00:51:50
|
Re http://docutils.sf.net/sandbox/richard/ZReST/, Richard Jones wrote: > Anyway, it works, mostly. It doesn't: > > 1. have any control over options > 2. have any capturing of Reporter output > > .. because I spent the better part of an hour trying to figure how I > could sanely control both, and gave up ;) Can you give us specifics, of what you want to do? Control options how? Capture Reporter output how? > There's probably some way of faking an options object, but I just > couldn't get it to fly... Why fake it? Isn't it easy to get a real one? > The Reporter stuff seemed far too hard-coded for my brain to cope > with at present :) Are you trying to capture the stderr output of Reporter, or the <system_message> elements it produces? Why? Anyhow, I appreciate the effort. You're exercising Docutils in a way it hasn't been exercised before, which brings out deficiencies. Like when you try to use muscles you don't ordinarily use, they hurt the next day. I see some places where the code is biased towards files and paths, which should be fixed. It should be easier to say, "Here's a reStructuredText string; give me HTML." Some comments on ZReST.render:: def render(self): ''' Render the source to HTML ''' # format with strings pub = core.Publisher() pub.set_reader('standalone', None, 'restructuredtext') pub.set_writer('html') # go with the defaults pub.set_options() # this is needed, but doesn't seem to do anything pub.options._destination = '' It's currently needed to calculate relative paths for the stylesheet link. But you shouldn't have to deal with it. It's one of the file-biased things I mentioned that needs fixing. # input pub.source = io.StringInput(pub.options) pub.source.source = self.source # output - not that it's needed pub.destination = io.StringOutput(pub.options) If it's not needed, use ``io.NullOutput``. You can access the data from ``pub.writer.astext()`` (produces Unicode). But further down, I see that you *do* need the ``StringOutput`` object; it does the output encoding (default UTF-8). # parse! document = pub.reader.read(pub.source, pub.parser, pub.options) # do the format self.formatted = pub.writer.write(document, pub.destination) Instead of these, you can just use:: self.formatted = pub.publish() BTW, I like the name. We all need more Z-rest. (If you don't get it, you're probably American. "Zee" indeed! ;-) -- David Goodger <go...@us...> Open-source projects: - Python Docutils: http://docutils.sourceforge.net/ (includes reStructuredText: http://docutils.sf.net/rst.html) - The Go Tools Project: http://gotools.sourceforge.net/ |