'use strict'
var emojiNamedCharacters = require('emoji-named-characters')
var marked = require('ssb-marked')
var ssbref = require('ssb-ref')
var mlib = require('ssb-msgs')
var renderer = new marked.Renderer();
// override to only allow external links or hashes, and correctly link to ssb objects
renderer.urltransform = function (url) {
var c = url.charAt(0)
var hasSigil = (c == '@' || c == '&' || c == '%')
if (this.options.sanitize && !hasSigil) {
try {
var prot = decodeURIComponent(unescape(url))
.replace(/[^\w:]/g, '')
.toLowerCase();
} catch (e) {
return false;
}
if (prot.indexOf('javascript:') === 0) {
return false;
}
}
var islink = ssbref.isLink(url)
if (hasSigil && !islink && this.options.mentionNames) {
// do a name lookup
url = this.options.mentionNames[url.slice(1)]
if (!url)
return false
islink = true
}
if (islink) {
if (ssbref.isFeedId(url))
return '#/profile/'+url
else if (ssbref.isMsgId(url))
return '#/msg/'+url
else if (ssbref.isBlobId(url))
return '#/webview/'+url
}
else if (url.indexOf('http') !== 0) {
return false;
}
return url
}
// override to make http/s links external
renderer.link = function(href, title, text) {
href = this.urltransform(href)
var out
if (href !== false)
out = '' + text + '';
return out;
};
// override to support