Changeset 219:854608cc314c

Show
Ignore:
Timestamp:
10/26/09 21:48:37 (11 months ago)
Author:
Daniele Varrazzo <piro@develer.com>
Tags:

tip

branch:
default
Message:

Convert relative urls into absolute in rendered ht pages.

Only convert links in the frame, leave links in the body untouched.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pythonit/siteapp/management/commands/ht2html.py

    r198 r219  
    99import sys 
    1010import os 
     11import re 
    1112from optparse import make_option 
    1213from os.path import abspath, dirname, join 
     
    7778        metadata = get_page_metadata(msg) 
    7879        body = get_page_body(msg) 
     80        # hack to convert relative links into absolute in the page frame 
     81        body = re.sub(r"""(?i)(href)(=['"]/)""", r'\1XXX\2', body) 
    7982 
    8083        class FakeRequest: 
     
    8992 
    9093        page = render_to_string('htpage.html', ctx) 
     94 
     95        # convert relative links into absolute and revert hacked links 
     96        page = re.sub(r"""(?i)(href=['"])/""", r'\1http://www.python.it/', page) 
     97        page = re.sub(r"""(?i)(href)XXX(=['"]/)""", r'\1\2', page) 
    9198        outfile = options['out'] and open(options['out'], 'w') or sys.stdout 
    9299        outfile.write(page.encode('utf-8'))