Ticket #150 (closed defect: fixed)

Opened 7 months ago

Last modified 7 weeks ago

htmlwriter failing on unknown attribute types

Reported by: jem Owned by: ralf
Priority: major Component: mwlib
Keywords: Cc:

Description (last modified by ralf) (diff)

htmlwriter.py fails when attempting to render an object of type "Caption". (gallery tags also do not render)

I'm not sure what a Caption is, but I would suggest at least the following patch:

--- a/mwlib/htmlwriter.py	Mon Feb 11 17:06:46 2008 +0100
+++ b/mwlib/htmlwriter.py	Sat May 31 15:54:33 2008 -0600
@@ -30,7 +30,7 @@ class HTMLWriter(object):
             self.math_renderer = math_renderer
     
     def _write(self, s):
-        self.out.write(cgi.escape(s))
+        self.out.write(cgi.escape(s.encode("utf8")))
 
     def getCategoryList(self, obj):
         categories = list(set(c.target for c in obj.find(parser.CategoryLink)))
@@ -39,7 +39,10 @@ class HTMLWriter(object):
                     
     def write(self, obj):
         m = "write" + obj.__class__.__name__
-        m=getattr(self, m)
+        m=getattr(self, m, None)
+        if not m:
+            log.warn("No method to write object:", obj.__class__.__name__)
+            return
         m(obj)
 
     def ignore(self, obj):}}}

Change History

Changed 7 months ago by ralf

yes, that makes sense. htmlwriter could sure need some love. Caption objects are currently only created for captions of tables.

Changed 7 months ago by ralf

  • description modified (diff)

Changed 7 months ago by ralf

jem, you might also want to have a look at:

http://dev.laptop.org/git?p=projects/wikiserver;a=blob;f=server.py;h=c4544c7d9512a02af15914c4e1e3fd2cf2f2c426;hb=HEAD#l140

(this is a link from a recent thread on the mailing list. they have written a subclass of htmlwriter with support for gallery tags)

Changed 7 months ago by wadeb

Our HTMLWriter has support for gallery tags, and we also patched our mwlib to handle caption (I think). And, it uses Wikipedia's monobook.css styling so it looks a bit more like the real thing.

Changed 7 months ago by wadeb

(ralf's above link is to the file that contains our HTMLWriter)

Changed 7 weeks ago by ralf

  • status changed from new to closed
  • resolution set to fixed

applied in mwlib:5623e767caa8. thanks.

Note: See TracTickets for help on using tickets.