git ssb

30+

cel / git-ssb-web



Commit 42ab59f09b0d717812b1d295880d411d4d4af0e9

Render markdown in blob view

Charles Lehner committed on 3/27/2016, 11:02:53 AM
Parent: 31c9fa39360b9c65460095352026a362be40c0ab

Files changed

index.jschanged
index.jsView
@@ -145,8 +145,18 @@
145145 ) +
146146 '</form>'
147147 }
148148
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+
149159 function readNext(fn) {
150160 var next
151161 return function (end, cb) {
152162 if (next) return next(end, cb)
@@ -250,8 +260,10 @@
250260 svg: 'image/svg+xml',
251261 bmp: 'image/bmp'
252262 }
253263
264+var markdownFilenameRegex = /\.md$|\/.markdown$/i
265+
254266 module.exports = function (opts, cb) {
255267 var ssb, reconnect, myId, getRepo, getVotes, getMsg, issues
256268 var about = function (id, cb) { cb(null, {name: id}) }
257269 var reqQueue = []
@@ -904,9 +916,9 @@
904916 repo.getObjectFromAny(file.id, function (err, obj) {
905917 if (err) return cb(err)
906918 cb(null, cat([
907919 pull.once('<section><h4>' + escapeHTML(file.name) + '</h4><hr/>'),
908- /\.md|\/.markdown/i.test(file.name) ?
920+ markdownFilenameRegex.test(file.name) ?
909921 readOnce(function (cb) {
910922 pull(obj.read, pull.collect(function (err, bufs) {
911923 if (err) return cb(err)
912924 var buf = Buffer.concat(bufs, obj.length)
@@ -1036,14 +1048,16 @@
10361048 '<h3>Files' + pathLinks + '</h3>' +
10371049 '<div>' + object.length + ' bytes' +
10381050 '<span class="raw-link">' + link(rawFilePath, 'Raw') + '</span>' +
10391051 '</div></section>' +
1040- '<section><pre>'),
1052+ '<section>'),
10411053 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>')
10461060 ])))
10471061 })
10481062 })
10491063 }

Built with git-ssb-web