aboutsummaryrefslogtreecommitdiff
path: root/lib/render.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-28 21:01:29 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-28 21:01:29 -1000
commit0e9903642e2e2c9cfb6f89f80a0256fa6f53ef5c (patch)
tree30bfa6e7ede6c125eec3a51cbef4892208b1f622 /lib/render.js
parentd8f6c6a19274cf53d9967d3597dd582ee7233ca3 (diff)
parentb66bcecec258b0a2631ec338501afa9409882fe8 (diff)
downloadpatchfoo-0e9903642e2e2c9cfb6f89f80a0256fa6f53ef5c.tar.gz
patchfoo-0e9903642e2e2c9cfb6f89f80a0256fa6f53ef5c.zip
Merge branch 'master' into votes
Diffstat (limited to 'lib/render.js')
-rw-r--r--lib/render.js54
1 files changed, 43 insertions, 11 deletions
diff --git a/lib/render.js b/lib/render.js
index ea94329..102035b 100644
--- a/lib/render.js
+++ b/lib/render.js
@@ -34,18 +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 '<a'
- + (href !== false
- ? ' href="' + href + '"'
- : ' class="bad"')
- + (title ? ' title="' + title + '"' : '')
- + (name ? ' download="' + encodeURIComponent(name) + '"' : '')
- + '>' + text + '</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 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)
@@ -132,6 +148,22 @@ Render.prototype.formatSize = function (size) {
return size.toFixed(2) + ' MB'
}
+Render.prototype.linkify = function (text) {
+ var arr = text.split(u.ssbRefEncRegex)
+ for (var i = 1; i < arr.length; i += 2) {
+ arr[i] = h('a', {href: this.toUrlEnc(arr[i])}, arr[i])
+ }
+ return arr
+}
+
+Render.prototype.toUrlEnc = function (href) {
+ var url = this.toUrl(href)
+ if (url) return url
+ try { href = decodeURIComponent(href) }
+ catch (e) { return false }
+ return this.toUrl(href)
+}
+
Render.prototype.toUrl = function (href) {
if (!href) return href
var mentions = this._mentions
@@ -186,7 +218,7 @@ Render.prototype.prepareLink = function (link, cb) {
if (link.name || !link.link) cb(null, link)
else this.app.getAbout(link.link, function (err, about) {
if (err) return cb(null, link)
- link.name = about.name || (link.link.substr(0, 8) + '…')
+ link.name = about.name || about.title || (link.link.substr(0, 8) + '…')
if (link.name && link.name[0] === link.link[0]) {
link.name = link.name.substr(1)
}