git ssb

0+

cel / ssb-mentions



Commit 27b98ddcb4a61a15e2b1b237e0ead0de6cd87798

Remove html from mention names

cel committed on 3/29/2017, 4:29:11 PM
Parent: 30816f2fc9f07da0bfa9b850793c83462b489489

Files changed

index.jschanged
test/mentions.jschanged
index.jsView
@@ -3,8 +3,31 @@
33 function noop(){}
44 var onLink = noop
55 var extractor = new marked.Renderer()
66
7 +// prevent html from entering into mention labels.
8 +// code taken from ssb-markdown
9 +extractor.code = function(code, lang, escaped) { return escaped ? unquote(code) : code }
10 +extractor.blockquote = function(quote) { return unquote(quote) }
11 +extractor.html = function(html) { return false }
12 +extractor.heading = function(text, level, raw) { return unquote(text)+' ' }
13 +extractor.hr = function() { return ' --- ' }
14 +extractor.br = function() { return ' ' }
15 +extractor.list = function(body, ordered) { return unquote(body) }
16 +extractor.listitem = function(text) { return '- '+unquote(text) }
17 +extractor.paragraph = function(text) { return unquote(text)+' ' }
18 +extractor.table = function(header, body) { return unquote(header + ' ' + body) }
19 +extractor.tablerow = function(content) { return unquote(content) }
20 +extractor.tablecell = function(content, flags) { return unquote(content) }
21 +extractor.strong = function(text) { return unquote(text) }
22 +extractor.em = function(text) { return unquote(text) }
23 +extractor.codespan = function(text) { return unquote(text) }
24 +extractor.del = function(text) { return unquote(text) }
25 +
26 +function unquote (text) {
27 + return text.replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, '\'')
28 +}
29 +
730 extractor.mention = function (_, id) {
831 onLink({target: id})
932 }
1033
test/mentions.jsView
@@ -67,4 +67,15 @@
6767 t.deepEquals(mentions('a nice #hashtag here'),
6868 [{link: '#hashtag'}], 'hashtag link')
6969 t.end()
7070 })
71 +
72 +test('no html tags in link names', function (t) {
73 + t.deepEquals(mentions('link: [`code` *em* **strong** ~~del~~]' +
74 + '(&9SSTQys34p9f4zqjxvRwENjFX0JapgtesRey7+fxK14=.sha256)'), [
75 + {
76 + link: '&9SSTQys34p9f4zqjxvRwENjFX0JapgtesRey7+fxK14=.sha256',
77 + name: 'code em strong del'
78 + }
79 + ], 'no tags')
80 + t.end()
81 +})

Built with git-ssb-web