From kkinder at rackspace.com Tue Oct 15 13:09:03 2002 From: kkinder at rackspace.com (Ken Kinder) Date: Tue Oct 15 13:09:03 2002 Subject: [Moin-devel] Formatter Troubles Message-ID: <1034712664.16262.10.camel@ken> I've had, and continue to have, a great deal of difficulty writing my own formatter. I have a mostly working DocBook/XML output formatter, and here's how it works: -- As particular methods are called on the formatter for the starting and ending of elements, I keep track of context. -- Each of these methods returns a blank string. -- The document is build through a minidom object that I have to build dynamicly by painstakingly construct by keeping track of the exact context of where I am in the document. -- I modified wiki.py to call formatter.rawtext() when it has raw unformatted text instead of using the formatter. That's the only way I can actually capture what's in between the tags. -- Nothing is outputted until document end. So, the problem is, I have text like foo *bar* What I get is: foo bar Through debug variables, I've absolutely confirmed that strong is called to open and close before "bar" is sent to rawtext. Why might this be? Are there any other pitfalls you can think of that are going to continue to bite me as a struggle mapping the way formatters work to the way building an XML file via DOM work? Thanks in advance. -Ken -- Ken Kinder Requirements Manager; Core Team -- Rackspace Managed Hosting(tm) 210-892-4025 x1095 From kkinder at rackspace.com Tue Oct 15 13:49:02 2002 From: kkinder at rackspace.com (Ken Kinder) Date: Tue Oct 15 13:49:02 2002 Subject: [Moin-devel] Current XML Formatter Message-ID: <1034715048.16262.16.camel@ken> By the way, the current MoinMoin formatter does not produce valid XML. That's why you should use DOM to build XML. This example Wiki page: = Section 1 = == Subsection 1.1 == Test Paragraph = Section 2 = Section 2 first '''paragraph''' Section 2 second paragraph Results in: "FooBar"

Test Paragraph Section 2 first paragraph

<--- ***** Wowowwow, you have to close s2 first!!

Section 2 second paragraph

This, again, is why you should use DOM -- that you why KNOW the XML is valid. Using DOM is what I'm trying to do for my docbook formatter. -- Ken Kinder Requirements Manager; Core Team -- Rackspace Managed Hosting(tm) 210-892-4025 x1095 From lele at seldati.it Tue Oct 15 14:48:02 2002 From: lele at seldati.it (Lele Gaifax) Date: Tue Oct 15 14:48:02 2002 Subject: [Moin-devel] Formatter Troubles In-Reply-To: <1034712664.16262.10.camel@ken> References: <1034712664.16262.10.camel@ken> Message-ID: <15788.36130.502570.120345@paci.nautilus> >>>>> On 15 Oct 2002 15:11:03 -0500, Ken Kinder said: KK> So, the problem is, I have text like KK> foo *bar* KK> What I get is: KK> foo bar KK> Through debug variables, I've absolutely confirmed that strong KK> is called to open and close before "bar" is sent to rawtext. KK> Why might this be? Are there any other pitfalls you can think KK> of that are going to continue to bite me as a struggle mapping KK> the way formatters work to the way building an XML file via KK> DOM work? This is the same thing that happens, in some circumstances, under PyApache. I guess it has something to do with the way moin emits its text, some time using sys.stdout.write, some time using print statements: some parts of moin replace sys.stdout to get the output of "subparts" (macros for example). I've spent some time to track the problem, with out luck. bye, lele. -- nickname: Lele Gaifax | Quando vivro' di quello che ho pensato ieri real: Emanuele Gaifas | comincero' ad aver paura di chi mi copia. email: lele at seldati.it | -- Fortunato Depero, 1929. From tbird20d at yahoo.com Tue Oct 15 16:43:01 2002 From: tbird20d at yahoo.com (Tim Bird) Date: Tue Oct 15 16:43:01 2002 Subject: [Moin-devel] Formatter Troubles In-Reply-To: <15788.36130.502570.120345@paci.nautilus> Message-ID: <20021015234211.80895.qmail@web20810.mail.yahoo.com> --- Lele Gaifax wrote: > >>>>> On 15 Oct 2002 15:11:03 -0500, Ken Kinder > said: > > KK> So, the problem is, I have text like > > KK> foo *bar* > > KK> What I get is: > > KK> foo bar > > KK> Through debug variables, I've absolutely confirmed that > strong > KK> is called to open and close before "bar" is sent to > rawtext. > > KK> Why might this be? Are there any other pitfalls you can > think > KK> of that are going to continue to bite me as a struggle > mapping > KK> the way formatters work to the way building an XML file via > KK> DOM work? > > This is the same thing that happens, in some circumstances, under > PyApache. I guess it has something to do with the way moin emits > its > text, some time using sys.stdout.write, some time using print > statements: some parts of moin replace sys.stdout to get the output > of > "subparts" (macros for example). > > I've spent some time to track the problem, with out luck. I'm just guessing, but maybe you need to flush whatever you're writing to, right after your write: sys.stdout.flush() With all the streams being replaced and substituted, I wouldn't be at all surprised to see stuff left in output buffers and not making to the network socket in program write order. Tim Bird __________________________________________________ Do you Yahoo!? Faith Hill - Exclusive Performances, Videos & More http://faith.yahoo.com From kkinder at rackspace.com Wed Oct 16 07:14:05 2002 From: kkinder at rackspace.com (Ken Kinder) Date: Wed Oct 16 07:14:05 2002 Subject: [Moin-devel] Formatter Troubles In-Reply-To: <20021015234211.80895.qmail@web20810.mail.yahoo.com> References: <20021015234211.80895.qmail@web20810.mail.yahoo.com> Message-ID: <1034777796.18832.4.camel@ken> On Tue, 2002-10-15 at 18:42, Tim Bird wrote: >> This is the same thing that happens, in some circumstances, under >> PyApache. I guess it has something to do with the way moin emits >> its text, some time using sys.stdout.write, some time using print >> statements: some parts of moin replace sys.stdout to get the output >> of "subparts" (macros for example). >> >> I've spent some time to track the problem, with out luck. > > I'm just guessing, but maybe you need to flush whatever you're > writing to, right after your write: > > sys.stdout.flush() > > With all the streams being replaced and substituted, I wouldn't > be at all surprised to see stuff left in output buffers and not > making to the network socket in program write order. > No, that really isn't it. I've confirmed that if I have: This part is normal. '''This part is bold.''' The method that invokes the strong highlighting *really*is* called before the method that prints the text: -- formatter.strong is called to open -- formatter.strong is called to close -- formatter.rawtext (one I added) is called with "This part is normal. This part is bold." You see, I don't actually print the text as I go. In order to make sure I produce proper XML, nothing is actually printed until formatter.endDocument. It seems that upon further investigation of the source code, the parser is calling the formatter on strong tags and then *inserting* whatever it returns into the text, before calling formatter.rawtext -- although this answers my question, it doesn't really solve my problem. I'm asking for advice on what the best way to build a document using DOM. This process doesn't seem to fit into the formatter method because of the problem I describe above. -- Ken Kinder Requirements Manager; Core Team -- Rackspace Managed Hosting(tm) 210-892-4025 x1095