diff --git a/index.js b/index.js index 2f3b69d..e547da7 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,12 @@ function noop(){} var onLink = noop var extractor = new marked.Renderer() +var keyRegex = /[0-9a-zA-Z\/+]{43}=/ + +function isKey(str) { + return keyRegex.test(str) +} + // prevent html from entering into mention labels. // code taken from ssb-markdown extractor.code = function(code, lang, escaped) { return escaped ? unquote(code) : code } @@ -61,8 +67,16 @@ module.exports = function (text, opts) { links(text, function (link) { if(ref.isFeed(link.target)) a.push({link: link.target, name: link.label && link.label.replace(/^@/, '')}) - else if(ref.isBlob(link.target)) - a.push({link: link.target, name: link.label}) + else if(link.target && link.target[0] === '&') { + var parts = link.target.split('#') + var hash = parts[0] + var key = parts[1] + if(ref.isBlob(hash)) { + link = {link: hash, name: link.label} + if(isKey(key)) link.key = key + a.push(link) + } + } else if(ref.isMsg(link.target)) a.push({link: link.target, name: link.label}) else if(bareFeedNames && link.target && link.target[0] === '@')