Ticket #1140: pagetopdf_local_attachments.diff

File pagetopdf_local_attachments.diff, 0.9 kB (added by eric@petta-tech.com, 2 years ago)

quick and dirty patch I wrote to workaround this problem

  • pagetopdf/pagetopdf.py

    old new  
    1515        yield ('pdf', 'PDF', 'pdf', 'text/x-trac-wiki', 'application/pdf', 7) 
    1616 
    1717    def convert_content(self, req, input_type, source, output_type): 
     18        local_attachment_path = '/usr/local/trac/attachments' 
    1819        hfile, hfilename = mkstemp('tracpdf') 
    1920        codepage = self.env.config.get('trac', 'default_charset', 0) 
    2021        page = wiki_to_html(source, self.env, req).encode(codepage) 
     22        page = re.sub('<img src="/trac/attachment/([^"?]+)(\?*[^"]*)"', 
     23                      r'<img  src="%s/\1"' % (local_attachment_path), 
     24                      page) 
    2125        page = re.sub('<img src="(?!\w+://)', '<img src="%s://%s:%d' % (req.scheme, req.server_name, req.server_port), page) 
    2226        os.write(hfile, '<html><body>' + page + '</body></html>') 
    2327        os.close(hfile)