From 9d8f3deef44af4d6b7508dfe557677293d2977ce Mon Sep 17 00:00:00 2001 From: cel Date: Wed, 18 Dec 2019 21:27:01 -0500 Subject: Show id in feed names in markdown-usable way If the feed name cannot be used as a @mention but must be a [@mention](@id), show it that way, so it can be copy-pastable into new message text. --- lib/render.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'lib/render.js') diff --git a/lib/render.js b/lib/render.js index e694396..df5d1c6 100644 --- a/lib/render.js +++ b/lib/render.js @@ -346,6 +346,32 @@ Render.prototype.idLink = function (link, cb) { return a } +// %NM8tXGBBDKKcpRbbyd/5uN1p/2OtBMFDylLMDPGoq8Q=.sha256 +var idRegex = /^[A-Za-z0-9._\-+=/]*[A-Za-z0-9_\-+=/]$/ + +Render.prototype.idLinkCopyable = function (link, cb) { + var self = this + if (!self.app.copyableIds) return idLink(link, cb) + if (!link) return cb(), '' + var a = h('a', ' ') + self.prepareLink(link, function (err, link) { + if (err) return cb(err) + a.href = self.toUrl(link.link) + var name = link.name || String(link.link).substr(1, 8) + '…' + if (idRegex.test(name)) a.childNodes[0].textContent = '@' + name + else { + a.className = 'id-copyable-link' + a.innerHTML = h('span', [ + h('span.id-deemphasize', '['), + h('span.id-name', '@' + link.name), + h('span.id-deemphasize', '](', link.link, ')'), + ]).innerHTML + } + cb() + }) + return a +} + Render.prototype.privateLine = function (recps, isAuthorRecp, cb) { var done = multicb({pluck: 1, spread: true}) var self = this -- cgit v1.2.3