Changeset 1504
- Timestamp:
- 03/25/08 10:16:18 (2 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid/PyLucid/middlewares/headline_anchor.py
r1503 r1504 27 27 28 28 HEADLINE = ( 29 '<h%(no)s id="%(anchor)s">'29 u'<h%(no)s id="%(anchor)s">' 30 30 '<a title="Link to this section" href="%(link)s#%(anchor)s" class="anchor">' 31 31 '%(txt)s</a>' … … 35 35 36 36 class HeadlineAnchor(object): 37 def process_ view(self, request, view_func, view_args, view_kwargs):37 def process_response(self, request, response): 38 38 """ 39 Add 39 Add anchors to every html headlines. 40 40 """ 41 # start the view42 response = view_func(request, *view_args, **view_kwargs)43 44 41 # Put only the statistic into HTML pages 45 42 if not "html" in response._headers["content-type"][1]: … … 60 57 self.anchor_list = [] 61 58 59 content = response.content 60 if not isinstance(content, unicode): 61 # FIXME: In my shared webhosting environment is response.content a 62 # string and not unicode. Why? 63 from django.utils.encoding import force_unicode 64 try: 65 content = force_unicode(content) 66 except: 67 return response 68 62 69 # add the anchor with re.sub 63 content = response.content64 70 new_content = HEADLINE_RE.sub(self.add_anchor, content) 65 71 response.content = new_content