From b90b36f54546b4bad7618a57e7f5484892e23b52 Mon Sep 17 00:00:00 2001 From: cel Date: Tue, 16 May 2017 08:21:42 -1000 Subject: Show local name in title for links to ids as suggested in %O4GCxFpucC3DeSTCuiR9GCha9g/NXbrQYm9iam5z1RE=.sha256 --- lib/app.js | 5 +++++ lib/render.js | 27 ++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/app.js b/lib/app.js index eee6c95..7b5bccc 100644 --- a/lib/app.js +++ b/lib/app.js @@ -191,6 +191,11 @@ App.prototype.getReverseNameSync = function (name) { return id } +App.prototype.getNameSync = function (name) { + var about = this.aboutCache.get(name) + return about && about.name +} + function getMsgWithValue(sbot, id, cb) { if (!id) return cb() sbot.get(id, function (err, value) { diff --git a/lib/render.js b/lib/render.js index 74b4f4f..dd6d55e 100644 --- a/lib/render.js +++ b/lib/render.js @@ -34,17 +34,34 @@ MdRenderer.prototype.image = function (ref, title, text) { }).outerHTML } -MdRenderer.prototype.link = function(href, title, text) { - href = this.urltransform(href) +MdRenderer.prototype.link = function (ref, title, text) { + var href = this.urltransform(ref) var name = href && /^\/(&|%26)/.test(href) && (title || text) - return h('a', { + if (u.isRef(ref)) { + var myName = this.render.app.getNameSync(ref) + if (myName) title = title ? title + ' (' + myName + ')' : myName + } + var a = h('a', { class: href === false ? 'bad' : undefined, href: href !== false ? href : undefined, title: title || undefined, download: name ? encodeURIComponent(name) : undefined - }, text).outerHTML -}; + }) + // text is already html-escaped + a.innerHTML = text + return a.outerHTML +} +MdRenderer.prototype.mention = function (preceding, id) { + var href = this.urltransform(id) + var myName = this.render.app.getNameSync(id) + if (id.length > 50) id = id.slice(0, 8) + '…' + return (preceding||'') + h('a', { + class: href === false ? 'bad' : undefined, + href: href !== false ? href : undefined, + title: myName || undefined, + }, id).outerHTML +} function lexerRenderEmoji(emoji) { var el = this.renderer.render.emoji(emoji) -- cgit v1.2.3