summaryrefslogtreecommitdiff
path: root/src/web
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-02-09 01:07:06 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-02-09 01:07:06 +0900
commita68efc1e5e1f14afe899f04ee75f76493da15baa (patch)
treef8baa2607dce080dc414b096d51d7272ef3a5e5e /src/web
parent[Client] いい感じにした (diff)
downloadsharkey-a68efc1e5e1f14afe899f04ee75f76493da15baa.tar.gz
sharkey-a68efc1e5e1f14afe899f04ee75f76493da15baa.tar.bz2
sharkey-a68efc1e5e1f14afe899f04ee75f76493da15baa.zip
nanka iroiro
Diffstat (limited to 'src/web')
-rw-r--r--src/web/app/common/scripts/text-compiler.js35
-rw-r--r--src/web/app/desktop/tags/timeline-post.tag17
2 files changed, 33 insertions, 19 deletions
diff --git a/src/web/app/common/scripts/text-compiler.js b/src/web/app/common/scripts/text-compiler.js
index 8ea2361b87..ab322764f3 100644
--- a/src/web/app/common/scripts/text-compiler.js
+++ b/src/web/app/common/scripts/text-compiler.js
@@ -1,12 +1,18 @@
const riot = require('riot');
const nyaize = require('nyaize').default;
-module.exports = function(tokens, shouldBreak, escape) {
+const escape = function(text) {
+ return text
+ .replace(/>/g, '&gt;')
+ .replace(/</g, '&lt;');
+};
+
+module.exports = function(tokens, shouldBreak, shouldEscape) {
if (shouldBreak == null) {
shouldBreak = true;
}
- if (escape == null) {
- escape = true;
+ if (shouldEscape != null) {
+ alert('do not use this option')
}
const me = riot.mixin('i').me;
@@ -14,26 +20,23 @@ module.exports = function(tokens, shouldBreak, escape) {
let text = tokens.map(function(token) {
switch (token.type) {
case 'text':
- if (escape) {
- return token.content
- .replace(/>/g, '&gt;')
- .replace(/</g, '&lt;')
- .replace(/(\r\n|\n|\r)/g, shouldBreak ? '<br>' : ' ');
- } else {
- return token.content
- .replace(/(\r\n|\n|\r)/g, shouldBreak ? '<br>' : ' ');
- }
+ return escape(token.content)
+ .replace(/(\r\n|\n|\r)/g, shouldBreak ? '<br>' : ' ');
case 'bold':
- return '<strong>' + token.bold + '</strong>';
+ return '<strong>' + escape(token.bold) + '</strong>';
case 'link':
- return '<mk-url href="' + token.content + '" target="_blank"></mk-url>';
+ return '<mk-url href="' + escape(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>';
+ return '<a href="' + CONFIG.url + '/' + escape(token.username) + '" target="_blank" data-user-preview="' + token.content + '">' + token.content + '</a>';
case 'hashtag': // TODO
- return '<a>' + token.content + '</a>';
+ return '<a>' + escape(token.content) + '</a>';
+ case 'code':
+ return '<pre><code>' + escape(token.code) + '</code></pre>';
}
}).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);
}
diff --git a/src/web/app/desktop/tags/timeline-post.tag b/src/web/app/desktop/tags/timeline-post.tag
index 0105617e0d..7d6f537c8c 100644
--- a/src/web/app/desktop/tags/timeline-post.tag
+++ b/src/web/app/desktop/tags/timeline-post.tag
@@ -30,11 +30,11 @@
</div>
</header>
<div class="body">
- <div class="text">
+ <div class="text" ref="text">
<a class="reply" if={ p.reply_to }>
<i class="fa fa-reply"></i>
</a>
- <span ref="text"></span>
+ <p>DUMMY</p>
<a class="quote" if={ p.repost != null }>RP:</a>
</div>
<div class="media" if={ p.media }>
@@ -228,6 +228,17 @@
font-style oblique
color #a0bf46
+ pre
+ padding 16px
+ overflow auto
+ font-size 80%
+ color #525252
+ background #f8f8f8
+ border-radius 2px
+
+ > code
+ font-family Consolas, 'Courier New', Courier, Monaco, monospace
+
> .media
> img
display block
@@ -304,7 +315,7 @@
then @analyze @p._highlight
else @analyze @p.text
- @refs.text.innerHTML = if @p._highlight?
+ @refs.text.innerHTML = @refs.text.innerHTML.replace \<p>DUMMY</p> if @p._highlight?
then @compile tokens, true, false
else @compile tokens