aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-16 08:21:42 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-16 16:25:06 -1000
commitb90b36f54546b4bad7618a57e7f5484892e23b52 (patch)
tree574f51e35c9543b7505e1dab360d396fc745ef0e
parent36dd4c128fa2b5b789542cb0a3f2b16231980fb4 (diff)
downloadpatchfoo-b90b36f54546b4bad7618a57e7f5484892e23b52.tar.gz
patchfoo-b90b36f54546b4bad7618a57e7f5484892e23b52.zip
Show local name in title for links to ids
as suggested in %O4GCxFpucC3DeSTCuiR9GCha9g/NXbrQYm9iam5z1RE=.sha256
-rw-r--r--lib/app.js5
-rw-r--r--lib/render.js27
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)