blob: 62e70463adb211ce830cc585e655bab56e685842 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
const riot = require('riot');
const nyaize = require('nyaize').default;
const escape = function(text) {
return text
.replace(/>/g, '>')
.replace(/</g, '<');
};
module.exports = function(tokens, shouldBreak, shouldEscape) {
if (shouldBreak == null) {
shouldBreak = true;
}
if (shouldEscape != null) {
alert('do not use this option')
}
const me = riot.mixin('i').me;
let text = tokens.map(function(token) {
switch (token.type) {
case 'text':
return escape(token.content)
.replace(/(\r\n|\n|\r)/g, shouldBreak ? '<br>' : ' ');
case 'bold':
return '<strong>' + escape(token.bold) + '</strong>';
case 'link':
return '<mk-url href="' + escape(token.content) + '" target="_blank"></mk-url>';
case 'mention':
return '<a href="' + CONFIG.url + '/' + escape(token.username) + '" target="_blank" data-user-preview="' + token.content + '" ' + (me && me.username == token.username ? 'data-is-me' : '') + '>' + token.content + '</a>';
case 'hashtag': // TODO
return '<a>' + escape(token.content) + '</a>';
case 'code':
return '<pre><code>' + token.html + '</code></pre>';
case 'inline-code':
return '<code>' + token.html + '</code>';
}
}).join('');
text = text.replace(/<br><code><pre>/g, '<code><pre>').replace(/<\/code><\/pre><br>/g, '</code></pre>');
if (me && me.data && me.data.nya) {
text = nyaize(text);
}
return text;
}
|