diff MoinMoin/formatter/text_html.py @ 2576:f4c371b00fec

refactor the ID generation/writing code
author Johannes Berg <johannes AT sipsolutions DOT net>
date Fri, 27 Jul 2007 11:37:37 +0200
parents ce0787373150
children 5e7b45489430
line wrap: on
line diff
--- a/MoinMoin/formatter/text_html.py	Fri Jul 27 11:37:15 2007 +0200
+++ b/MoinMoin/formatter/text_html.py	Fri Jul 27 11:37:37 2007 +0200
@@ -338,11 +338,13 @@
         id = None
         if not is_unique:
             if attr and 'id' in attr:
-                attr['id'] = self.make_id_unique(attr['id'])
-                id = attr['id']
+                id = self.make_id_unique(attr['id'])
+                id = self.qualify_id(id)
+                attr['id'] = id
             if 'id' in kw:
-                kw['id'] = self.make_id_unique(kw['id'])
-                id = kw['id']
+                id = self.make_id_unique(kw['id'])
+                id = self.qualify_id(id)
+                kw['id'] = id
         else:
             if attr and 'id' in attr:
                 id = attr['id']
@@ -561,7 +563,8 @@
         # line-numbered code sections (from line_achordef() method).
         #return '<a id="%s"></a>' % (id, ) # do not use - this breaks PRE sections for IE
         id = self.make_id_unique(id)
-        return '<span class="anchor" id="%s"></span>' % wikiutil.escape(id, 1)
+        id = self.qualify_id(id)
+        return '<span class="anchor" id="%s"></span>' % id
 
     def line_anchordef(self, lineno):
         if line_anchors:
@@ -585,11 +588,8 @@
         """
         attrs = self._langAttr()
         if name:
-            if self.request.include_id:
-                attrs['href'] = '#%s.%s' % (
-                    wikiutil.anchor_name_from_text(self.request.include_id), name)
-            else:
-                attrs['href'] = '#%s' % name
+            name = self.sanitize_to_id(name)
+            attrs['href'] = '#' + self.qualify_id(name)
         if 'href' in kw:
             del kw['href']
         if on:
@@ -915,7 +915,7 @@
         must be unique within the document.  The show, start, and step are
         used for line numbering.
 
-B        Note this is not like most formatter methods, it can not take any
+        Note this is not like most formatter methods, it can not take any
         extra keyword arguments.
 
         Call once with on=1 to start the region, and a second time
@@ -924,7 +924,9 @@
         _ = self.request.getText
         res = []
         if on:
-            ci = self.make_id_unique('CA-%s' % code_id)
+            code_id = self.sanitize_to_id('CA-%s' % code_id)
+            ci = self.qualify_id(self.make_id_unique(code_id))
+
             # Open a code area
             self._in_code_area = 1
             self._in_code_line = 0
@@ -1361,3 +1363,5 @@
             return self._open(tag, **kw)
         return self._close(tag)
 
+    def sanitize_to_id(self, text):
+        return wikiutil.anchor_name_from_text(text)