diff options
author | cel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519> | 2020-03-25 10:57:51 -0400 |
---|---|---|
committer | cel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519> | 2020-03-28 13:55:36 -0400 |
commit | 4ee97dfaa67cc8ab77bbac574f0d05c6d60f4e37 (patch) | |
tree | 7e85d67e0e97c51f5b3d6bfa80b81ee7d61d4b56 /lib/render.js | |
parent | 646e70a38f1daae390271c3ad65c4b6c0d87de5f (diff) | |
download | patchfoo-4ee97dfaa67cc8ab77bbac574f0d05c6d60f4e37.tar.gz patchfoo-4ee97dfaa67cc8ab77bbac574f0d05c6d60f4e37.zip |
Render descriptions as diffs in gathering threads
Diffstat (limited to 'lib/render.js')
-rw-r--r-- | lib/render.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/render.js b/lib/render.js index 5d8fd66..7c2cf64 100644 --- a/lib/render.js +++ b/lib/render.js @@ -13,6 +13,7 @@ var multicb = require('multicb') var RenderMsg = require('./render-msg') var Highlight = require('highlight.js') var md = require('ssb-markdown') +var Diff = require('diff') module.exports = Render @@ -719,3 +720,46 @@ Render.prototype.friendsList = function (prefix) { } ) } + +Render.prototype.textEditDiffTable = function (oldMsg, newMsg) { + var oldC = oldMsg && oldMsg.value.content || {} + var newC = newMsg && newMsg.value.content || {} + var oldText = String(oldC.text || oldC.description || '') + var newText = String(newC.text || newC.description || '') + var diff = Diff.structuredPatch('', '', oldText, newText) + var self = this + return h('table', [ + diff.hunks.map(function (hunk) { + var oldLine = hunk.oldStart + var newLine = hunk.newStart + return [ + h('tr', [ + h('td', {colspan: 2}), + h('td', h('pre', + '@@ -' + oldLine + ',' + hunk.oldLines + ' ' + + '+' + newLine + ',' + hunk.newLines + ' @@')) + ]), + hunk.lines.map(function (line) { + var s = line[0] + if (s == '\\') return + var lineNums = [s == '+' ? '' : oldLine++, s == '-' ? '' : newLine++] + return [ + h('tr', { + class: s == '+' ? 'diff-new' : s == '-' ? 'diff-old' : '' + }, [ + lineNums.map(function (num, i) { + return h('td', String(num)) + }), + h('td', {innerHTML: + h('code', s).outerHTML + + u.unwrapP(self.markdown(line.substr(1), + s == '-' ? oldC.mentions : newC.mentions)) + }) + ]) + ] + }) + ] + }) + ]) +} + |