25433f9f53f3

Fix relative links and encoding in preview
[view raw] [browse files]
author constantine <theaspect@gmail.com>
date Thu, 10 Oct 2013 10:59:07 +0700
parents 42f23a3f2f1b
children 2dbe1ce3f693
branches/tags (none)
files __init__.py

Changes

--- a/__init__.py	Thu Oct 10 10:58:42 2013 +0700
+++ b/__init__.py	Thu Oct 10 10:59:07 2013 +0700
@@ -22,15 +22,16 @@
     parts = os.path.splitext(f)
 
     try:
-        text = codecs.open(web.repo.root + "/" + f, "rb", "utf-8").read()
+        text = codecs.open(web.repo.root + "/" + f, "rb").read()
     except IOError:
         raise ErrorResponse(HTTP_NOT_FOUND, 'path not found: ' + f)
 
     if not parts[-1] == '.markdown' and not parts[-1] == '.md':
         return preview_sendraw(web, req, f, text)
 
-    base_url = tmpl.defaults['url'] + 'preview/'
-    base_raw_url = tmpl.defaults['url'] + 'preview/'
+    relative_path = os.path.split(f)[0]
+    base_url = tmpl.defaults['url'] + 'preview/' + relative_path
+    base_raw_url = tmpl.defaults['url'] + 'preview/' + relative_path
 
     def rebase(proc, e, attr):
         uri = e.get(attr, '')
@@ -46,7 +47,7 @@
             extensions=[ext, 'wikilinks','toc','headerid','attr_list'],
             extension_configs={
                 'wikilinks' : [('base_url', ""), ('end_url', parts[-1])]})
-    html = md.convert(text).encode("utf-8")
+    html = md.convert(text.decode(encoding.encoding)).encode("utf-8")
 
     args = {'file':f,
             'readmefilename':parts[0].split('/')[-1],