var path = require('path') var url = require('url') var marked = require('ssb-marked') var ref = require('ssb-ref') var u = require('./util') var emojiNamedCharacters = require('emoji-named-characters') // render links to git objects and ssb objects var blockRenderer = new marked.Renderer() blockRenderer.urltransform = function (href) { if (ref.isLink(href)) return u.encodeLink(href) if (/^[0-9a-f]{40}$/.test(href) && this.options.repo) return u.encodeLink([this.options.repo.id, 'commit', href]) if (this.options.repo && this.options.rev && this.options.path && !url.parse(href).host && href[0] !== '#') return path.join('/', encodeURIComponent(this.options.repo.id), 'blob', this.options.rev, this.options.path.join('/'), href) return href } blockRenderer.image = function (href, title, text) { href = href.replace(/^&/, '&') var url if (ref.isBlobId(href)) url = u.encodeLink(href) else if (/^https?:\/\//.test(href)) url = href else if (this.options.repo && this.options.rev && this.options.path) url = path.join('/', encodeURIComponent(this.options.repo.id), 'raw', this.options.rev, this.options.path.join('/'), href) else return text return '' } blockRenderer.mention = function (preceding, id) { // prevent broken name mention if (id[0] == '@' && !ref.isFeed(id)) return (preceding||'') + u.escape(id) return marked.Renderer.prototype.mention.call(this, preceding, id) } blockRenderer.listitem = function (text, checked) { return '