From: David G. <go...@py...> - 2013-09-17 14:11:36
|
On 16 September 2013 20:21, Roberto Alsina <ra...@ne...> wrote: > Hello! > > I want to integrate docutils' error reporting into my own app's so that > I can show the users a meaningful error report after processing a batch > of files. > > One possible way to do it would be to use my own reporter class instead > of docutils.utils.Reporter. > > I can monkeypatch it but I'd rather not :-) > > So, the question is: Is there a way to tell docutils to use my reporter > when using publish_programatically? Currently there is no clean way to hook the creation of Reporter instances. The easiest thing to override is docutils.readers.Reader.new_document (take the result and replace document.reporter with your object), but even that's a kludge. I suggest either: a) adding a "reporter=None" parameter to docutils.core.Publisher.__init__ (as well as publish_programatically and the convenience functions that call publish_programatically or create a Publisher instance), and pass that through the chain down to docutils.utils.new_document; or b) add it to the "settings" object, which gets passed down through the chain. Option (a) is a bit draconian, and would affect many projects depending on Docutils. Option (b) is much nicer that way, but a bit kludgey. There's also option (c): come up with something better. :-) Once you come up with something, please submit a patch and we'll get it in, or you can commit it yourself after discussion. (Don't have the commit bit? You should.) -- David Goodger <http://python.net/~goodger> |