diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2016-12-29 07:49:51 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2016-12-29 07:49:51 +0900 |
| commit | b3f42e62af698a67c2250533c437569559f1fdf9 (patch) | |
| tree | cdf6937576e99cccf85e6fa3aa8860a1173c7cfb /src/web/app/common/scripts/text-compiler.js | |
| download | misskey-b3f42e62af698a67c2250533c437569559f1fdf9.tar.gz misskey-b3f42e62af698a67c2250533c437569559f1fdf9.tar.bz2 misskey-b3f42e62af698a67c2250533c437569559f1fdf9.zip | |
Initial commit :four_leaf_clover:
Diffstat (limited to 'src/web/app/common/scripts/text-compiler.js')
| -rw-r--r-- | src/web/app/common/scripts/text-compiler.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/web/app/common/scripts/text-compiler.js b/src/web/app/common/scripts/text-compiler.js new file mode 100644 index 0000000000..9915e3335f --- /dev/null +++ b/src/web/app/common/scripts/text-compiler.js @@ -0,0 +1,30 @@ +module.exports = function(tokens, canBreak, escape) { + if (canBreak == null) { + canBreak = true; + } + if (escape == null) { + escape = true; + } + return tokens.map(function(token) { + 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(''); +} |