5a8c3dda25ee

Fix relative links rebase
[view raw] [browse files]
author constantine@gmail.com
date Tue, 08 Oct 2013 00:02:43 +0700
parents ade5266185db
children ea6a7cfcacd8
branches/tags (none)
files ReadMe.markdown __init__.py relative/doca.md relative/docb.md relative/logo.png

Changes

--- a/ReadMe.markdown	Sun Oct 06 17:36:21 2013 +0700
+++ b/ReadMe.markdown	Tue Oct 08 00:02:43 2013 +0700
@@ -13,6 +13,14 @@
 [WikiLinks](http://packages.python.org/Markdown/extensions/wikilinks.html) extension
 to support documentation split across several pages.
 
+You can add relative links to [nested](relative/doca.md) pages, or to current [headers](#config),
+or even to images 
+_(actually at BitBucket relative links are
+[broken](https://bitbucket.org/site/master/issue/6315/relative-urls-in-readmemd-files-only-work) 
+and you don't see logo, but hgext.markdown can do it :)_
+
+![logo](relative/logo.png)
+
 ##Install##
 
 1. Install Python-Markdown (http://packages.python.org/Markdown/install.html)
--- a/__init__.py	Sun Oct 06 17:36:21 2013 +0700
+++ b/__init__.py	Tue Oct 08 00:02:43 2013 +0700
@@ -80,7 +80,6 @@
     f = req.form.get('file', [''])[0]
     parts = os.path.splitext(f)
 
-
     if 'file' not in req.form:
         return webcommands.manifest(web, req, tmpl)
 
@@ -100,8 +99,9 @@
     if util.binary(text):
         return webcommands.rawfile(web, req, tmpl)
 
-    base_url = tmpl.defaults['url'] + 'file/' + changeid + "/"
-    base_raw_url = tmpl.defaults['url'] + 'rawfile/' + changeid + "/"
+    relative_path = os.path.split(f)[0]
+    base_url = tmpl.defaults['url'] + 'file/' + changeid + "/" + relative_path
+    base_raw_url = tmpl.defaults['url'] + 'rawfile/' + changeid + "/" + relative_path
 
     def rebase(proc, e, attr):
         uri = e.get(attr, '')
@@ -113,7 +113,7 @@
         e.set(attr, proc.rebase(base, uri))
 
     ext = mdx_urlrebase.UrlRebaseExtension(configs=[('rebase', rebase)])
-    md = markdown.Markdown(
+    md = Markdown(
             extensions=[ext, 'wikilinks','toc','headerid','attr_list'],
             extension_configs={
                 'wikilinks' : [('base_url', ""), ('end_url', parts[-1])]})
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/relative/doca.md	Tue Oct 08 00:02:43 2013 +0700
@@ -0,0 +1,4 @@
+#Relative links demo
+
+- [Sibling page B](docb.md)
+- [Parent page](../ReadMe.markdown)
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/relative/docb.md	Tue Oct 08 00:02:43 2013 +0700
@@ -0,0 +1,4 @@
+#Relative links demo
+
+- [Sibling page A](doca.md)
+- [Parent page](../ReadMe.markdown)
\ No newline at end of file
Binary file relative/logo.png has changed