git ssb

16+

cel / patchfoo



Tree: b614cb87e82036808f31e0940b9a67f609212fe4

Files: b614cb87e82036808f31e0940b9a67f609212fe4 / lib / markdown-inline.js

2034 bytesRaw
1var marked = require('ssb-marked')
2var u = require('./util')
3var unquote = u.unescapeHTML
4
5// based on ssb-markdown, which is Copyright (c) 2016 Dominic Tarr, MIT License
6
7var inlineRenderer = new marked.Renderer()
8
9// inline renderer just spits out the text of links and images
10inlineRenderer.urltransform = function (url) { return url }
11inlineRenderer.link = function (href, title, text) { return unquote(shortenIfLink(text)) }
12inlineRenderer.image = function (href, title, text) { return unquote(shortenIfLink(text)) }
13inlineRenderer.code = function(code, lang, escaped) { return escaped ? unquote(code) : code }
14inlineRenderer.blockquote = function(quote) { return unquote(quote) }
15inlineRenderer.html = function(html) { return html }
16inlineRenderer.heading = function(text, level, raw) { return unquote(text)+' ' }
17inlineRenderer.hr = function() { return ' --- ' }
18inlineRenderer.br = function() { return ' ' }
19inlineRenderer.list = function(body, ordered) { return unquote(body) }
20inlineRenderer.listitem = function(text) { return '- '+unquote(text) }
21inlineRenderer.paragraph = function(text) { return unquote(text)+' ' }
22inlineRenderer.table = function(header, body) { return unquote(header + ' ' + body) }
23inlineRenderer.tablerow = function(content) { return unquote(content) }
24inlineRenderer.tablecell = function(content, flags) { return unquote(content) }
25inlineRenderer.strong = function(text) { return unquote(text) }
26inlineRenderer.em = function(text) { return unquote(text) }
27inlineRenderer.codespan = function(text) { return unquote(text) }
28inlineRenderer.del = function(text) { return unquote(text) }
29inlineRenderer.mention = function(preceding, id) { return shortenIfLink(unquote((preceding||'') + id)) }
30inlineRenderer.hashtag = function(preceding, tag) { return unquote((preceding||'') + tag) }
31
32function shortenIfLink (text) {
33 return (u.ssbRefRegexOnly.test(text.trim())) ? text.slice(0, 8) : text
34}
35
36module.exports = function(text) {
37 return marked(''+(text||''), {renderer: inlineRenderer, emoji: false})
38}
39

Built with git-ssb-web