# HG changeset patch # User theaspect@gmail.com # Date 1368506687 -25200 # Node ID 68c3007cd59dc5ef8d9883f1f69005d5f6c518db # Parent c49ba42e5f0e80663fae36755cb5c83130bd37ac Add url rebase of images in files diff -r c49ba42e5f0e -r 68c3007cd59d __init__.py --- a/__init__.py Mon May 13 21:22:16 2013 +0700 +++ b/__init__.py Tue May 14 11:44:47 2013 +0700 @@ -70,6 +70,7 @@ try: fctx = webutil.filectx(web.repo, req) + changeid = fctx.hex()[0:12] text = fctx.data().decode("utf-8") except ErrorResponse, inst: try: @@ -80,7 +81,23 @@ if util.binary(text): return webcommands.rawfile(web, req, tmpl) - md = markdown.Markdown(extensions=['wikilinks(base_url={0},end_url={1})'.format('', parts[1])]) + base_url = tmpl.defaults['url'] + 'file/' + changeid + "/" + base_raw_url = tmpl.defaults['url'] + 'rawfile/' + changeid + "/" + + def rebase(proc, e, attr): + uri = e.get(attr, '') + if '://' in uri 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'], + extension_configs={ + 'wikilinks' : [('base_url', ""), ('end_url', parts[-1])]}) html = md.convert(text).encode("utf-8") args = {'file':f,