af6d0c8414f2

Merged celdredge/hgext.markdown into default
[view raw] [browse files]
author Constantine Linnick <theaspect@gmail.com>
date Mon, 20 May 2013 22:02:59 +0700
parents 68c3007cd59d (diff) 4d384cd08fc8 (current diff)
children 0c5a7b4e6613
branches/tags (none)
files __init__.py

Changes

--- a/__init__.py	Mon May 13 21:49:24 2013 +0100
+++ b/__init__.py	Mon May 20 22:02:59 2013 +0700
@@ -74,6 +74,7 @@
 
 	try:
 		fctx = webutil.filectx(web.repo, req)
+		changeid = fctx.hex()[0:12]
 		text = fctx.data().decode("utf-8")
 	except LookupError, inst:
 		try:
@@ -84,7 +85,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,