about summary refs log tree commit diff
path: root/app/javascript/mastodon/rtl.js
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-06-10 15:06:50 +0200
committerGitHub <noreply@github.com>2017-06-10 15:06:50 +0200
commit8015fd76003419bd3ccca585ffe4416312800fe0 (patch)
treef1995858c87e85827e2ef3267aa61d3f2bed6f8b /app/javascript/mastodon/rtl.js
parent4919b89ab83f8eee43b89ff4786eae46bf2fa30e (diff)
Improve RTL detection (#3682)
- Use plaintext
- Strip out URLs
- Strip out mentions
- Strip out hashtags
- Strip out whitespace from "overall" count
- Consistent between JS and Ruby
Diffstat (limited to 'app/javascript/mastodon/rtl.js')
-rw-r--r--app/javascript/mastodon/rtl.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/app/javascript/mastodon/rtl.js b/app/javascript/mastodon/rtl.js
index 8f14bb338..00870a15d 100644
--- a/app/javascript/mastodon/rtl.js
+++ b/app/javascript/mastodon/rtl.js
@@ -17,11 +17,15 @@ export function isRtl(text) {
     return false;
   }
 
+  text = text.replace(/(?:^|[^\/\w])@([a-z0-9_]+(@[a-z0-9\.\-]+)?)/ig, '');
+  text = text.replace(/(?:^|[^\/\w])#([\S]+)/ig, '');
+  text = text.replace(/\s+/g, '');
+
   const matches = text.match(rtlChars);
 
   if (!matches) {
     return false;
   }
 
-  return matches.length / text.trim().length > 0.3;
+  return matches.length / text.length > 0.3;
 };