Commit 3fac22a4a27f3a65427e7f145c9f55db93a0b795
Link markdown links to ssb refs
cel committed on 4/7/2017, 11:17:29 PMParent: c12cf209d49b72ac4627e8082069e5baf259a9aa
Files changed
markdown.js | changed |
package.json | changed |
markdown.js | ||
---|---|---|
@@ -3,8 +3,10 @@ | ||
3 | 3 … | var html = require('remark-html') |
4 | 4 … | var slug = require('remark-slug') |
5 | 5 … | var autolinkHeadings = require('remark-autolink-headings') |
6 | 6 … | var com = require('./tmpl/com.part') |
7 … | +var select = require('unist-util-select') | |
8 … | +var ssbRef = require('ssb-ref') | |
7 | 9 … | |
8 | 10 … | const linkSvg = '<svg aria-hidden="true" class="octicon octicon-link" height="16" role="img" version="1.1" viewBox="0 0 16 16" width="16"><path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path></svg>' |
9 | 11 … | |
10 | 12 … | module.exports.doc = function (path) { |
@@ -17,8 +19,9 @@ | ||
17 | 19 … | }) |
18 | 20 … | .use(html) |
19 | 21 … | .use(injectTOC) |
20 | 22 … | .use(transformCodeExamples) |
23 … | + .use(transformSsbLinks) | |
21 | 24 … | .process(text) |
22 | 25 … | } |
23 | 26 … | |
24 | 27 … | // find all h2s and create a dropdown table-of-contents |
@@ -98,4 +101,16 @@ | ||
98 | 101 … | }) |
99 | 102 … | |
100 | 103 … | return com.code(codes) |
101 | 104 … | } |
105 … | + | |
106 … | +// add a prefix to links to ssb refs | |
107 … | +function transformSsbLinks (remark, options) { | |
108 … | + return ast => { | |
109 … | + select(ast, "link").forEach(link => { | |
110 … | + if (ssbRef.isLink(link.url)) { | |
111 … | + link.url = 'https://git.scuttlebot.io/' + link.url | |
112 … | + } | |
113 … | + }) | |
114 … | + return ast | |
115 … | + } | |
116 … | +} |
Built with git-ssb-web