From: Waylan L. <wa...@gm...> - 2009-01-28 15:30:30
|
On Wed, Jan 28, 2009 at 1:02 AM, Matthias Urlichs <sm...@sm...> wrote: > Hi, > > Waylan Limberg: >> Do we want to set the format for the class (in "__init__") or per call to "convert". >> > s/instead/do both/. > > My rationale for this is that I want an instance that's set up the way I > want to have it set up for the common case, and be able to override > the format for specific output formats. Think "HTML web site with > Atom feed", for example. > Hi Matthias, Thanks for your feedback. Upon further thought, I had come to the same conclusion, more-or-less. The fact is, when running multiple documents through a single instant of the Markdown class, a user may already need to call other methods on the instance (such as reset), so, if the "output_format" is a property of the class, that can be changed between calls to ``convert`` if needed. I'm thinking of doing something like this: md = Markdown(output_format="html4") html = md.convert(some_text) md.set_output_format("xhtml") # <-- note this line xhtml = md.convert(some_text) Now, I could just do ``md.output_format = "xhtml", but I think I'm going to have the method actually assign the appropriate serializer as a property of the class. Something like: def set_output_format(self, format): if format in ['html', 'html4']: self.serializer = html4.tostring if format in ['xhtml', 'xhtml1]: self.serializer in etree.tostring This way someone *could* override/replace the serializer with their own (say html5) and output any format they wanted. Or, if due to licensing issues, markdown gets distributed without the html4 serializer (by Debian for example), there's still an easy way for someone to add their own etc. Any thoughts on this approach? Just to be clear, we would *not recommend* people replace the serializer (as it may break existing extensions etc), but making it possible adds one more layer of extendability. For example, someone *might* write an extension which replaces the serializer and all postprocessors for an output_format that it not anything like html (pdf or latex come to mind). How easy or difficult it would be to write such an extension, I don't know, but at least it would be possible. That's more than can be said now. -- ---- \X/ /-\ `/ |_ /-\ |\| Waylan Limberg |