changeset 333:5bfac46824a6

fixed MoinMoinBugs/FootNotesProduceInvalidHtml; changed FootNote macro to use formatter, changed text_python formatter to use result.append() for building the python source, added __adjust_formatter_state() to the end of the page content to make the formatter work correctly within the footer (and the foot notes) imported from: moin--main--1.5--patch-337
author Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
date Sun, 18 Dec 2005 20:26:06 +0000
parents 0a40d8a4057e
children 259b384a7ce7
files MoinMoin/formatter/text_python.py MoinMoin/macro/FootNote.py
diffstat 2 files changed, 36 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/formatter/text_python.py	Sun Dec 18 20:14:48 2005 +0000
+++ b/MoinMoin/formatter/text_python.py	Sun Dec 18 20:26:06 2005 +0000
@@ -42,19 +42,6 @@
     def assemble_code(self, text):
         """inserts the code into the generated text
         """
-        #text = text.replace('\\', '\\\\')
-        #text = text.replace('"', '\\"')
-        text = text.split('<<<>>>', len(self.code_fragments))
-        source = self.text_cmd_begin + repr(text[0])
-        i = 0
-        for t in text[1:]:
-            source = (source + self.text_cmd_end +
-                      self.code_fragments[i] +
-                      self.text_cmd_begin + repr(text[i+1]))
-            i = i + 1
-        source = source + self.text_cmd_end
-        self.code_fragments = [] # clear code fragments to make
-                                 # this object reusable
         # Automatic invalidation due to moin code changes:
         # we are called from Page.py, so moincode_timestamp is
         # mtime of MoinMoin directory. If we detect, that the
@@ -65,13 +52,28 @@
         # MoinMoin, so better do a touch if you only modified stuff
         # in a subdirectory.
         waspcode_timestamp = int(time.time())
-        source = """
+        source = ["""
 moincode_timestamp = int(os.path.getmtime(os.path.dirname(__file__)))
 if moincode_timestamp > %d or request.cfg.cfg_mtime > %d:
     raise "CacheNeedsUpdate"
-%s
-""" % (waspcode_timestamp, waspcode_timestamp, source)
-        return source
+""" % (waspcode_timestamp, waspcode_timestamp)]
+
+
+        text = text.split('<<<>>>', len(self.code_fragments))
+        source.extend([self.text_cmd_begin, repr(text[0])])
+        i = 0
+        for t in text[1:]:
+            source.extend([self.text_cmd_end,
+                           self.code_fragments[i],
+                           self.text_cmd_begin,
+                           repr(text[i+1])])
+            i = i + 1
+        source.append(self.text_cmd_end)
+        source.append(self.__adjust_formatter_state())
+        
+        self.code_fragments = [] # clear code fragments to make
+                                 # this object reusable
+        return "".join(source)
 
     def __getattr__(self, name):
         """ For every thing we have no method/attribute use the formatter
--- a/MoinMoin/macro/FootNote.py	Sun Dec 18 20:14:48 2005 +0000
+++ b/MoinMoin/macro/FootNote.py	Sun Dec 18 20:26:06 2005 +0000
@@ -47,36 +47,38 @@
         # inline tags will be closed, and we get correct direction.
         attr = formatter.langAttr()
         attr['class'] = 'footnotes'
-        result.append(formatter.open('div', attr=attr))
-
-        # What is that empty div for???
-        result.append('<div></div>\n')
+        attr = [' %s="%s"' % (k, v) for k, v in attr.items()]
+        result.append(formatter.rawHTML('<div%s>' % ''.join(attr)))
 
         # Add footnotes list
-        result.append('<ul>\n')
+        result.append(formatter.bullet_list(1))
         for idx in range(len(request.footnotes)):
             # Add item
+            result.append(formatter.listitem(1))
+            result.append(formatter.paragraph(1)) # see [1]
+            
             fn_id = request.footnotes[idx][1]
-            fn_no = (formatter.anchorlink(1, 'fnref' + fn_id, id = 'fndef' + fn_id) +
-                     formatter.text(str(idx+1)) +
-                     formatter.anchorlink(0))
-
-            result.append('<li><span>%s</span>' % fn_no)
+            result.append(formatter.anchorlink(1, 'fnref' + fn_id,
+                                               id='fndef' + fn_id))
+            result.append(formatter.text(str(idx+1)))
+            result.append(formatter.anchorlink(0))
+            result.append(formatter.text(" "))
                         
             out=StringIO.StringIO()
             request.redirect(out)
-            parser=wiki.Parser(request.footnotes[idx][0], request)
+            parser=wiki.Parser(request.footnotes[idx][0], request,
+                               line_anchors=False)
             parser.format(formatter)
             result.append(out.getvalue())
             request.redirect()
             del out
+            # [1] paragraph is automagically closed by wiki parser! 
+            result.append(formatter.listitem(0))
             
-            result.append('</li>\n')
-            
-        result.append('</ul>\n')
+        result.append(formatter.bullet_list(0))
 
         # Finish div
-        result.append(formatter.close('div'))
+        result.append(formatter.rawHTML('</div>'))
 
         request.footnotes = []
         return ''.join(result)