about summary refs log tree commit diff
path: root/app/javascript/mastodon/features/compose/util/counter.js
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-07-29 00:06:29 +0200
committerGitHub <noreply@github.com>2017-07-29 00:06:29 +0200
commit53b2b1b2389c0ea941c50d4a9c726539d808c384 (patch)
tree2afc8cc342a62aa66f4ab52b82a7f8fdf182cd67 /app/javascript/mastodon/features/compose/util/counter.js
parent634b71ed1d551ee569e5ff5b858ea7eb07c824bd (diff)
Count all URLs in text as 23 characters flat, do not count domain part of usernames (#4427)
* Count all URLs in text as 23 characters flat, do not count domain part of usernames

* Add new status text counting logic to web UI
Diffstat (limited to 'app/javascript/mastodon/features/compose/util/counter.js')
-rw-r--r--app/javascript/mastodon/features/compose/util/counter.js7
1 files changed, 7 insertions, 0 deletions
diff --git a/app/javascript/mastodon/features/compose/util/counter.js b/app/javascript/mastodon/features/compose/util/counter.js
new file mode 100644
index 000000000..589e85460
--- /dev/null
+++ b/app/javascript/mastodon/features/compose/util/counter.js
@@ -0,0 +1,7 @@
+const urlPlaceholder = 'xxxxxxxxxxxxxxxxxxxxxxx';
+
+export function countableText(inputText) {
+  return inputText
+    .replace(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g, urlPlaceholder)
+    .replace(/(?:^|[^\/\w])@(([a-z0-9_]+)@[a-z0-9\.\-]+)/ig, '@$2');
+};