--- a/__init__.py Sat Jun 01 16:35:16 2013 +0700
+++ b/__init__.py Sat Jun 01 17:09:39 2013 +0700
@@ -28,18 +28,34 @@
except IOError:
raise ErrorResponse(HTTP_NOT_FOUND, 'path not found: ' + f)
- if not parts[1] == '.markdown' and not parts[1] == '.md':
+ if not parts[-1] == '.markdown' and not parts[-1] == '.md':
return preview_sendraw(web, req, f, text)
- md = markdown.Markdown(extensions=['wikilinks(base_url={0},end_url={1})'.format('', parts[1])])
+ base_url = tmpl.defaults['url'] + 'preview/'
+ base_raw_url = tmpl.defaults['url'] + 'preview/'
+
+ def rebase(proc, e, attr):
+ uri = e.get(attr, '')
+ if '://' in uri or uri.startswith('/') or uri.startswith('#'):
+ return
+ base = base_url
+ if attr == 'src':
+ base = base_raw_url
+ e.set(attr, proc.rebase(base, uri))
+
+ ext = mdx_urlrebase.UrlRebaseExtension(configs=[('rebase', rebase)])
+ md = markdown.Markdown(
+ extensions=[ext, 'wikilinks','toc','headerid','attr_list'],
+ extension_configs={
+ 'wikilinks' : [('base_url', ""), ('end_url', parts[-1])]})
html = md.convert(text).encode("utf-8")
args = {'file':f,
'readmefilename':parts[0].split('/')[-1],
'path':webutil.up(f),
'readme':html,
- 'rev':'PREVIEW',
- 'node':'PREVIEW'}
+ 'rev':'tip',
+ 'node':''}
return tmpl("markdown", **args)
@@ -58,8 +74,9 @@
if mt.startswith('text/'):
mt += '; charset="%s"' % encoding.encoding
- req.respond(HTTP_OK, mt, path, len(data))
- return [data]
+ mt += '; Content-length="%s"' % len(data)
+ req.respond(HTTP_OK, mt, path, data)
+ return data
def file_markdown(orig, web, req, tmpl):
f = req.form.get('file', [''])[0]