aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)