Commit 42ab59f09b0d717812b1d295880d411d4d4af0e9
Render markdown in blob view
Charles Lehner committed on 3/27/2016, 11:02:53 AMParent: 31c9fa39360b9c65460095352026a362be40c0ab
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -145,8 +145,18 @@ | ||
145 | 145 | ) + |
146 | 146 | '</form>' |
147 | 147 | } |
148 | 148 | |
149 | +function wrap(tag) { | |
150 | + return function (read) { | |
151 | + return cat([ | |
152 | + pull.once('<' + tag + '>'), | |
153 | + read, | |
154 | + pull.once('</' + tag + '>') | |
155 | + ]) | |
156 | + } | |
157 | +} | |
158 | + | |
149 | 159 | function readNext(fn) { |
150 | 160 | var next |
151 | 161 | return function (end, cb) { |
152 | 162 | if (next) return next(end, cb) |
@@ -250,8 +260,10 @@ | ||
250 | 260 | svg: 'image/svg+xml', |
251 | 261 | bmp: 'image/bmp' |
252 | 262 | } |
253 | 263 | |
264 | +var markdownFilenameRegex = /\.md$|\/.markdown$/i | |
265 | + | |
254 | 266 | module.exports = function (opts, cb) { |
255 | 267 | var ssb, reconnect, myId, getRepo, getVotes, getMsg, issues |
256 | 268 | var about = function (id, cb) { cb(null, {name: id}) } |
257 | 269 | var reqQueue = [] |
@@ -904,9 +916,9 @@ | ||
904 | 916 | repo.getObjectFromAny(file.id, function (err, obj) { |
905 | 917 | if (err) return cb(err) |
906 | 918 | cb(null, cat([ |
907 | 919 | pull.once('<section><h4>' + escapeHTML(file.name) + '</h4><hr/>'), |
908 | - /\.md|\/.markdown/i.test(file.name) ? | |
920 | + markdownFilenameRegex.test(file.name) ? | |
909 | 921 | readOnce(function (cb) { |
910 | 922 | pull(obj.read, pull.collect(function (err, bufs) { |
911 | 923 | if (err) return cb(err) |
912 | 924 | var buf = Buffer.concat(bufs, obj.length) |
@@ -1036,14 +1048,16 @@ | ||
1036 | 1048 | '<h3>Files' + pathLinks + '</h3>' + |
1037 | 1049 | '<div>' + object.length + ' bytes' + |
1038 | 1050 | '<span class="raw-link">' + link(rawFilePath, 'Raw') + '</span>' + |
1039 | 1051 | '</div></section>' + |
1040 | - '<section><pre>'), | |
1052 | + '<section>'), | |
1041 | 1053 | extension in imgMimes |
1042 | - ? pull.once('<img src="' + escapeHTML(flattenPath(rawFilePath)) + | |
1043 | - '" alt="' + escapeHTML(filename) + '" />') | |
1044 | - : pull(object.read, escapeHTMLStream()), | |
1045 | - pull.once('</pre></section>') | |
1054 | + ? pull.once('<img src="' + escapeHTML(flattenPath(rawFilePath)) + | |
1055 | + '" alt="' + escapeHTML(filename) + '" />') | |
1056 | + : markdownFilenameRegex.test(filename) | |
1057 | + ? pull(object.read, escapeHTMLStream(), pull.map(markdown)) | |
1058 | + : pull(object.read, escapeHTMLStream(), wrap('pre')), | |
1059 | + pull.once('</section>') | |
1046 | 1060 | ]))) |
1047 | 1061 | }) |
1048 | 1062 | }) |
1049 | 1063 | } |
Built with git-ssb-web