diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-05-16 08:21:42 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-05-16 16:25:06 -1000 |
commit | b90b36f54546b4bad7618a57e7f5484892e23b52 (patch) | |
tree | 574f51e35c9543b7505e1dab360d396fc745ef0e /lib | |
parent | 36dd4c128fa2b5b789542cb0a3f2b16231980fb4 (diff) | |
download | patchfoo-b90b36f54546b4bad7618a57e7f5484892e23b52.tar.gz patchfoo-b90b36f54546b4bad7618a57e7f5484892e23b52.zip |
Show local name in title for links to ids
as suggested in %O4GCxFpucC3DeSTCuiR9GCha9g/NXbrQYm9iam5z1RE=.sha256
Diffstat (limited to 'lib')
-rw-r--r-- | lib/app.js | 5 | ||||
-rw-r--r-- | lib/render.js | 27 |
2 files changed, 27 insertions, 5 deletions
@@ -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) |