git ssb

30+

cel / git-ssb-web



Commit f02ae4c23a9eadb45073011f0eccc983a27e5343

Rewrite relative links in markdown

This makes links in READMEs point to the right things
Charles Lehner committed on 4/25/2016, 2:58:01 AM
Parent: 5fd4aa9b06699a4902c338327f26c760c9225157

Files changed

lib/markdown.jschanged
lib/markdown.jsView
@@ -1,17 +1,22 @@
11 var path = require('path')
2+var url = require('url')
23 var marked = require('ssb-marked')
34 var ref = require('ssb-ref')
45 var u = require('./util')
56
67 // render links to git objects and ssb objects
78 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
1419 }
1520
1621 blockRenderer.image = function (href, title, text) {
1722 href = href.replace(/^&/, '&')

Built with git-ssb-web