2016-12-30 03:57:17 +01:00
|
|
|
const riot = require('riot');
|
|
|
|
|
2016-12-28 23:49:51 +01:00
|
|
|
module.exports = function(tokens, canBreak, escape) {
|
|
|
|
if (canBreak == null) {
|
|
|
|
canBreak = true;
|
|
|
|
}
|
|
|
|
if (escape == null) {
|
|
|
|
escape = true;
|
|
|
|
}
|
2016-12-30 03:57:17 +01:00
|
|
|
|
|
|
|
const me = riot.mixin('i').me;
|
|
|
|
|
|
|
|
let text = tokens.map(function(token) {
|
2016-12-28 23:49:51 +01:00
|
|
|
switch (token.type) {
|
|
|
|
case 'text':
|
|
|
|
if (escape) {
|
|
|
|
return token.content
|
|
|
|
.replace(/>/g, '>')
|
|
|
|
.replace(/</g, '<')
|
|
|
|
.replace(/(\r\n|\n|\r)/g, canBreak ? '<br>' : ' ');
|
|
|
|
} else {
|
|
|
|
return token.content
|
|
|
|
.replace(/(\r\n|\n|\r)/g, canBreak ? '<br>' : ' ');
|
|
|
|
}
|
|
|
|
case 'bold':
|
|
|
|
return '<strong>' + token.bold + '</strong>';
|
|
|
|
case 'link':
|
|
|
|
return '<mk-url href="' + token.content + '" target="_blank"></mk-url>';
|
|
|
|
case 'mention':
|
|
|
|
return '<a href="' + CONFIG.url + '/' + token.username + '" target="_blank" data-user-preview="' + token.content + '">' + token.content + '</a>';
|
|
|
|
case 'hashtag': // TODO
|
|
|
|
return '<a>' + token.content + '</a>';
|
|
|
|
}
|
|
|
|
}).join('');
|
2016-12-30 03:57:17 +01:00
|
|
|
|
|
|
|
if (me && me.data && me.data.nya) {
|
2016-12-30 04:27:50 +01:00
|
|
|
text = text.replace(/な/g, 'にゃ')
|
|
|
|
.replace(/にゃでにゃで/g, 'なでなで');
|
2016-12-30 03:57:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
2016-12-28 23:49:51 +01:00
|
|
|
}
|