summary refs log tree commit diff
path: root/webclient/app-filter.js
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2014-10-17 17:33:58 +0100
committerMark Haines <mark.haines@matrix.org>2014-10-17 17:33:58 +0100
commitdc3c2823ac425c9b5bbe6883b7d33a12059a08fb (patch)
tree22d02a68df93c3f98b0be7de8a07040268420369 /webclient/app-filter.js
parentRename 'meta' to 'unsigned' (diff)
parentkeep 'origin_server_ts' as 'ts' in the database to avoid needlessly updating ... (diff)
downloadsynapse-dc3c2823ac425c9b5bbe6883b7d33a12059a08fb.tar.xz
Merge branch 'develop' into event_signing
Conflicts:
	synapse/federation/replication.py
Diffstat (limited to 'webclient/app-filter.js')
-rw-r--r--webclient/app-filter.js57
1 files changed, 53 insertions, 4 deletions
diff --git a/webclient/app-filter.js b/webclient/app-filter.js
index fc16492ef3..39ea1d637d 100644
--- a/webclient/app-filter.js
+++ b/webclient/app-filter.js
@@ -1,12 +1,12 @@
 /*
  Copyright 2014 OpenMarket Ltd
- 
+
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
- 
+
  http://www.apache.org/licenses/LICENSE-2.0
- 
+
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -80,4 +80,53 @@ angular.module('matrixWebClient')
     return function(text) {
         return $sce.trustAsHtml(text);
     };
-}]);
\ No newline at end of file
+}])
+// Exactly the same as ngSanitize's linky but instead of pushing sanitized
+// text in the addText function, we just push the raw text.
+.filter('unsanitizedLinky', ['$sanitize', function($sanitize) {
+  var LINKY_URL_REGEXP =
+        /((ftp|https?):\/\/|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s.;,(){}<>"]/,
+      MAILTO_REGEXP = /^mailto:/;
+
+  return function(text, target) {
+    if (!text) return text;
+    var match;
+    var raw = text;
+    var html = [];
+    var url;
+    var i;
+    while ((match = raw.match(LINKY_URL_REGEXP))) {
+      // We can not end in these as they are sometimes found at the end of the sentence
+      url = match[0];
+      // if we did not match ftp/http/mailto then assume mailto
+      if (match[2] == match[3]) url = 'mailto:' + url;
+      i = match.index;
+      addText(raw.substr(0, i));
+      addLink(url, match[0].replace(MAILTO_REGEXP, ''));
+      raw = raw.substring(i + match[0].length);
+    }
+    addText(raw);
+    return $sanitize(html.join(''));
+
+    function addText(text) {
+      if (!text) {
+        return;
+      }
+      html.push(text);
+    }
+
+    function addLink(url, text) {
+      html.push('<a ');
+      if (angular.isDefined(target)) {
+        html.push('target="');
+        html.push(target);
+        html.push('" ');
+      }
+      html.push('href="');
+      html.push(url);
+      html.push('">');
+      addText(text);
+      html.push('</a>');
+    }
+  };
+}]);