diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-02-21 11:11:17 -0500 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-02-21 11:11:17 -0500 |
commit | aa81a0cc95f894b695fb2585d8dae18b086b6cfe (patch) | |
tree | 07fef7140d900388cfd7589c86e8575d6b2a8706 | |
parent | 0ac4adbe515bf050246e466d65b3c3c77b093d6e (diff) | |
download | patchfoo-aa81a0cc95f894b695fb2585d8dae18b086b6cfe.tar.gz patchfoo-aa81a0cc95f894b695fb2585d8dae18b086b6cfe.zip |
Improve git commit message rendering
- Render as markdown unless it looks like it is plain text
- Linkify commit titles
- Linkify ssb://% URLs
-rw-r--r-- | lib/render-msg.js | 13 | ||||
-rw-r--r-- | lib/render.js | 1 | ||||
-rw-r--r-- | lib/util.js | 2 |
3 files changed, 12 insertions, 4 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js index 8bd3661..51d094e 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -377,15 +377,22 @@ RenderMsg.prototype.gitUpdate = function (cb) { h('ul', self.c.commits.map(function (commit) { return h('li', h('code', String(commit.sha1).substr(0, 8)), ' ', - commit.title, - commit.body ? h('div', - {innerHTML: self.render.markdown('\n' + commit.body)}) : '' + self.linkify(String(commit.title)), + self.gitCommitBody(commit.body) ) })) : '' ), cb) }) } +RenderMsg.prototype.gitCommitBody = function (body) { + if (!body) return '' + var isMarkdown = !/^# Conflicts:$/m.test(body) + return isMarkdown + ? h('div', {innerHTML: this.render.markdown('\n' + body)}) + : h('pre', this.linkify('\n' + body)) +} + RenderMsg.prototype.gitPullRequest = function (cb) { var self = this var done = multicb({pluck: 1, spread: true}) diff --git a/lib/render.js b/lib/render.js index 0cc96c6..573f5d8 100644 --- a/lib/render.js +++ b/lib/render.js @@ -100,6 +100,7 @@ Render.prototype.toUrl = function (href) { if (!href) return href var mentions = this._mentions if (mentions && href in this._mentions) href = this._mentions[href] + if (/^ssb:\/\//.test(href)) href = href.substr(6) switch (href[0]) { case '%': return this.opts.base + encodeURIComponent(href) case '@': diff --git a/lib/util.js b/lib/util.js index fe7a335..b94ebc2 100644 --- a/lib/util.js +++ b/lib/util.js @@ -3,7 +3,7 @@ var cat = require('pull-cat') var h = require('hyperscript') var u = exports -u.ssbRefRegex = /((?:@|%|&)[A-Za-z0-9\/+]{43}=\.[\w\d]+)/g +u.ssbRefRegex = /((?:@|%|&|ssb:\/\/%)[A-Za-z0-9\/+]{43}=\.[\w\d]+)/g u.isRef = function (str) { u.ssbRefRegex.lastIndex = 0 |