Commit f02ae4c23a9eadb45073011f0eccc983a27e5343
Rewrite relative links in markdown
This makes links in READMEs point to the right thingsCharles Lehner committed on 4/25/2016, 2:58:01 AM
Parent: 5fd4aa9b06699a4902c338327f26c760c9225157
Files changed
lib/markdown.js | changed |
lib/markdown.js | ||
---|---|---|
@@ -1,17 +1,22 @@ | ||
1 | 1 | var path = require('path') |
2 | +var url = require('url') | |
2 | 3 | var marked = require('ssb-marked') |
3 | 4 | var ref = require('ssb-ref') |
4 | 5 | var u = require('./util') |
5 | 6 | |
6 | 7 | // render links to git objects and ssb objects |
7 | 8 | var blockRenderer = new marked.Renderer() |
8 | -blockRenderer.urltransform = function (url) { | |
9 | - if (ref.isLink(url)) | |
10 | - return u.encodeLink(url) | |
11 | - if (/^[0-9a-f]{40}$/.test(url) && this.options.repo) | |
12 | - return u.encodeLink([this.options.repo.id, 'commit', url]) | |
13 | - return url | |
9 | +blockRenderer.urltransform = function (href) { | |
10 | + if (ref.isLink(href)) | |
11 | + return u.encodeLink(href) | |
12 | + if (/^[0-9a-f]{40}$/.test(href) && this.options.repo) | |
13 | + return u.encodeLink([this.options.repo.id, 'commit', href]) | |
14 | + if (this.options.repo && this.options.rev && this.options.path | |
15 | + && !url.parse(href).host) | |
16 | + return path.join('/', encodeURIComponent(this.options.repo.id), | |
17 | + 'blob', this.options.rev, this.options.path.join('/'), href) | |
18 | + return href | |
14 | 19 | } |
15 | 20 | |
16 | 21 | blockRenderer.image = function (href, title, text) { |
17 | 22 | href = href.replace(/^&/, '&') |
Built with git-ssb-web